Is it possible to use jQuery .on and hover?

前端 未结 10 880
失恋的感觉
失恋的感觉 2020-11-22 11:03

I have a

    that is populated with javascript after the initial page load. I\'m currently using .bind with mouseover and
10条回答
  •  -上瘾入骨i
    2020-11-22 11:40

    I'm not sure what the rest of your Javascript looks like, so I won't be able to tell if there is any interference. But .hover() works just fine as an event with .on().

    $("#foo").on("hover", function() {
      // disco
    });
    

    If you want to be able to utilize its events, use the returned object from the event:

    $("#foo").on("hover", function(e) {
      if(e.type == "mouseenter") {
        console.log("over");
      }
      else if (e.type == "mouseleave") {
        console.log("out");
      }
    });
    

    http://jsfiddle.net/hmUPP/2/

提交回复
热议问题