I know about the attributeContains selector, but how does it apply to style attributes?
I want to find all <a>
tags that have their opacity set to 0.
I tried this :
$("a[style*='opacity: 0']")
But it returns nothing.
To change the opacity of a div using JavaScript, get reference to the div element, and assign required opacity value to the element. style. opacity property. Opacity value ranges from 0 to 1.
The . fadeTo() method animates the opacity of the matched elements.
Definition and Usage The opacity property sets or returns the opacity level of an element. The opacity-level of an element describes the transparency-level, where 1 is not transperant at all, 0.5 is 50% see-through, and 0 is completely transparent.
Definition and Usage. The fadeTo() method gradually changes the opacity, for selected elements, to a specified opacity (fading effect).
The :visible
selector will not work because it doesn't give consideration to opacity.
To target just those with a 0
opacity, you could use a .filter()
to check the .css()
value of the opacity:
$("a").filter( function() {
return $(this).css('opacity') === '0';
});
You could create your own selector if you'd like:
$.extend($.expr[':'], {
opacity: function(elem, i, attr){
return( $(elem).css("opacity") === attr[3] + '' );
}
});
var $invisible = $("a:opacity(0)");
or
$.extend($.expr[':'], {
transparent: function(elem, i, attr){
return( $(elem).css("opacity") === "0" );
}
});
var $invisible = $("a:transparent");
If you want to know whether or not an element is visible, use:
$('a:not(:visible)');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With