george george - 24 days ago 5x
HTML Question

Check if element has empty class

I have a problem how to check if an element has empty class ... I tried the code below , but it's not working.

<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])')){




You can merely do this:

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

where I think that comments are not necessary...