Jquery check attribute element value
3 answers
The problem is that you mix jQuery and vanilla JS methods here, with .attr().display. You are also trying to compare an entire string stylewith (if that worked) a single CSS rule.
The best way to achieve this would be to use the jQuery method is()along with the selector :visible. Try the following:
if ($(this).closest('li').is(':visible')) {
// script
}
+6
, , , none, css(). .attr('style'), .
if($(this).closest('li').css('display') == 'none' ){
}
demonstrative ( , ):
$('li').each(function(i) {
if ($(this).css('display') == 'none') {
console.log(i); // logs the indexes of the hidden elements
}
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li style="padding-bottom: 0px; display: none;">
<span> Content </span>
</li>
<li style="padding-bottom: 0px; display: none;">
<span> Content </span>
</li>
<li style="padding-bottom: 0px;">
<span> Content </span>
</li>0