Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery check the attribute element value [duplicate]

<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

like image 881
Developer Avatar asked Feb 02 '17 08:02

Developer


1 Answers

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
}
like image 113
Rory McCrossan Avatar answered Oct 13 '22 00:10

Rory McCrossan