jquery hover().addClass() problem

后端 未结 4 717
南笙
南笙 2021-01-07 04:31

http://jsfiddle.net/aBaw6/2/

This demo does not add class when you hover a list item.

What am I doing wrong here?

$(\"li\").hover(
  function         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 05:09

    Your JavaScript was badly formed:

    $("li").hover(
      function () {
        $(this).addClass('hover);
      }, 
      function () {
        $(this).removeClass("hover");
      }
    );
    

    Should be:

    $("li").hover(
      function () {
        $(this).addClass('hover');
      }, 
      function () {
        $(this).removeClass('hover');
      }
      );
    

    If you click on the JS Lint button to the top of the screen it would've told you this (this isn't intended as a criticism, just a note for your future use of JS Fiddle).

提交回复
热议问题