tags:

views:

308

answers:

4

How do I select an element based on its css?

I need to select a br with inline style display:none. This is not the same thing as br:hidden, because that selects elements that are hidden in other ways, and I don't want that.

Thanks.

+3  A: 

You could try:

$("br").filter(function() { return $(this).css("display") == "none" })
T B
+4  A: 

Using filter.

$("br").filter(function () {
    return $(this).attr("display") == "none";
});
chelmertz
Not sure why this is getting upvoted since it will not work! It needs to be the CSS attribute and not an attribute on the HTML element
T B
A: 

Use jQuery.map:

var brs = $('br');
jQuery.map(brs, function(elem, i){
    if(elem.css('display') == 'none')
        return elem;
    return null;
});
Adam Bard
Actually filter's probably better.
Adam Bard
A: 

How about something like this:

$(document).ready(function() { $("div:hidden").each(function() { // do something if the following matches if ($(this).css("display") == "none") { } }); });

spig