Adding class to all divs not containing an element
I need to add a class to every div (with ID #myDiv) NOT containing an <li>-Tag.
I have:
- function checkEmptyDiv() {
- $("div #myDiv").each(function () {
- if ($(this).find("li").length == 0) {
- // $(this).addClass("hasNoLi");
- $(this).parents("div:first").addClass("hasNoLi");
- }
- });}
Line 5 doesn't add the class to the div.
Any suggestions?
Thx