我有以下HTML代码:
<style>
.thing { color: red }
</style>
<p class="thing">This is a nice thing</p>
我想更改当前所有内容和以后通过 AJAX 加载到页面的所有内容的“.thing”样式。
$('.thing').css('color', 'blue');
这个方法是可行的,但如果通过AJAX向文档添加新的HTML代码,则所有“.thing”元素仍将被涂成红色。
我想要的是更改整个文档的“.thing”样式属性,而不仅仅是当前元素(使用jQuery选择器)。
谢谢!
$("<style>").text(".thing {color:blue;}").appendTo("head");
示例。 - user113716