Pavel Yermalovich
Pavel Yermalovich

Reputation: 2000

How to select checkboxes with opacity:0.5

How to select checkboxes with opacity: 0.5?

Selector :checkbox[style~='opacity: 0.5'] doesn't select them.

Upvotes: 2

Views: 587

Answers (2)

kapa
kapa

Reputation: 78731

The filter() method lets you write a function that will run for all the elements and will only include them in the result set if the function returns true.

$('input[type="checkbox"]').filter(function () {
    return $(this).css('opacity') == 0.5;
}).addClass('marked');​

This will add a "marked" class on every element with 0.5 opacity.

Note: You should use classes instead of manipulating and querying CSS directly from Javascript.

Upvotes: 4

David Fernandez
David Fernandez

Reputation: 175

try this:

$('input').filter(function() {
     return $(this).css('opacity') == '0.5';
});

Upvotes: 2

Related Questions