I am trying to check whether two child divs contain content and if they do not ie they are empty then I would like to add a class to their parent div.
This is my code but this adds the class=”noBorder” to the parent div if the child divs are empty or not.
if(('div.nav-previous:empty') && ('div.nav-next:empty')) {
jQuery('div#nav-below').addClass('noBorder')
};
Any help with this would be much appreciated.
Gina
That’s because a jQuery selector will always return a value, regardless of whether it matched anything.
The above will return an empty array which will evaluate to TRUE.
Whenever you want to check if jQuery has returned a set of elements, you must check the length property: