Developer Developer - 4 years ago 143
HTML Question

jquery check the attribute element value

<li style="padding-bottom: 0px; display: none;">
<span> Content </span>
</li>


i want to check
display == none


i got the solution with the below script.

if($(this).closest('li').attr('style') =='padding-bottom: 0px; display: none;'){
// script
}


any other simple way to write.
Thanks

Answer Source

The issue you have is that you're mixing jQuery and vanilla JS methods here, with .attr().display. You're also trying to compare the whole style string against (if it worked) one CSS rule.

A better method of achieving this would be to use jQuery's is() method, along with the :visible selector. Try this:

if ($(this).closest('li').is(':visible')) {
  // script
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download