Adding class to all divs not containing an element

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:

  1. function checkEmptyDiv() {
  2.               $("div #myDiv").each(function () {
  3.                   if ($(this).find("li").length == 0) {
  4.                       //                      $(this).addClass("hasNoLi");
  5.                       $(this).parents("div:first").addClass("hasNoLi");
  6.                   }
  7.               });}
Line 5 doesn't add the class to the div.
Any suggestions?

Thx