Select all elements that have a specific CSS, using jQuery

Solution 1:

This is a two year old thread, but it was still useful to me so it could be useful to others, perhaps. Here's what I ended up doing:

var x = $('.myselector').filter(function () { 
    return this.style.some_prop == 'whatever' 
});

not as succinct as I would like, but I have never needed something like this except now, and it's not very efficient for general use anyway, as I see it.

Solution 2:

Thank you, Bijou. I used your solution, but used the jQuery .css instead of pure javascript, like this:

var x = $('*').filter(function() {
    return $(this).css('font-family').toLowerCase().indexOf('futura') > -1
})

This example would select all elements where the font-family attribute value contains "Futura".

Solution 3:

You cannot (using a CSS selector) select elements based on the CSS properties that have been applied to them.

If you want to do this manually, you could select every element in the document, loop over them, and check the computed value of the property you are interested in (this would probably only work with real CSS properties though, not made up ones such as rounded). It would also would be slow.

Update in response to edits — group selectors:

$(".Title, .Caption").corner();