开发者

Find all elements with matched set of values of specificed CSS property with jQuery?

开发者 https://www.devze.com 2023-03-13 01:02 出处:网络
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?

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" || ... ; 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消