给定一些HTML字符串,使用,JQuery如何搜索包含的所有样式,例如font-family:courier
<span style='font-family:courier;'>
<p style='font-family:courier;'>
并将其更改为font-family:courier new ?,结果:
<span style='font-family:courier new;'> 2</span>
<p style='font-family:courier new;'>
答案 0 :(得分:5)
如果您的HTML 完全,就像您给出的那样......
$('[style="font-family:courier;"]').css({fontFamily: "courier new"});
答案 1 :(得分:2)
您可以使用 .filter() :
$('*').filter(function () {
return $(this).css('font-family') == "courier"
}).css('font-family', 'courier new');
<强> Fiddle Demo 强>