george george - 1 year ago 100
HTML Question

How to 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 doesn't work.

<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