george george - 1 year ago 134
jQuery Question

jquery check if element has empty class

Hello guys i have a problem how to check if element has empty class ... I tried the code below , but its not working. Some advices would be welcomed.

<nav id="main-nav" class="">
<li><a href=""><i class="fa fa-pencil-square-o" aria-hidden="true"></i> references</a></li>
<li><a href=""><i class="fa fa-male" aria-hidden="true"></i> about me</a></li>
<li><a href=""><i class="fa fa-wrench" aria-hidden="true"></i> abilities</a></li>

if ($('#main-nav:not([class])')){



Answer Source

You can merely do this:

var $elem = $('#main-nav');
if (!$elem.attr('class')) {

where I think that comments are not necessary...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download