-2

I've been reading this thread: Style parent li on child li:hover and trying to get it to work with my menu in this fiddle: http://jsfiddle.net/PJMyR/1/, but it keeps throwing syntax errors at me, and I can't figure out why.

Here is the code:

$('li.parent ul li').mouseenter(function() {
    $(this).parent().closest('li.parent').addClass('highlighted');
}).mouseleave(function() {
    $(this).parent().closest('li.parent').removeClass('highlighted');
});

Best regards Martin

Community
  • 1
  • 1

1 Answers1

0

It works fine . Use .toggleClass for make your code simpler

$(function() {

    $('li.parent ul li').hover(function() {

        $(this).closest('li.parent').toggleClass('highlighted');

      });
});

DEMO

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49