I want to find all elements in the web page which has the CSS property "font" with one of the values "700, 800, 900, bold, bolder". How can I do this with jQuery?
<a href="http://google.com" style="font:bold;">Google</a>
<p style="font:bolder;">Test</p>
<div style="font:700;">Test</div&g开发者_运维问答t;
This ought to do it:
var elements = $("*").filter(function () {
var options = ["700", "800", "900", "bold", "bolder"];
return $.inArray($(this).css('font-weight'), options) > -1;
});
Now you can manipulate your list of elements:
elements.css('background', '#f00'); // Highlights all elements with red bg.
See the jQuery documentation for examples of how you can manipulate your DOM.
You could do this:
$("*").filter(function() {
return $(this).css("font-weight") == "bolder" ||
$(this).css("font-weight") == "bold" || ... ;
});
精彩评论