1$( "td" ).hover(
2 () => { //hover
3 $(this).addClass("hover");
4 },
5 () => { //out
6 $(this).removeClass("hover");
7 }
8);
9
10//or
11$( "td" )
12 .mouseover( () => {
13 $(this).addClass("hover");
14 })
15 .mouseout( () => {
16 $(this).removeClass("hover");
17 }
18);
19
20//or
21$( "td" )
22 .mouseenter( () => {
23 $(this).addClass("hover");
24 })
25 .mouseleave( () => {
26 $(this).removeClass("hover");
27 }
28);
1$( "div.enterleave" )
2 .mouseenter(function() {
3 n += 1;
4 $( this ).find( "span" ).text( "mouse enter x " + n );
5 })
6 .mouseleave(function() {
7 $( this ).find( "span" ).text( "mouse leave" );
8 });
1$(document).ready(function() {
2 $("p").hover(function() {
3 $(this).css("background-color", "green");
4 }, function() {
5 $(this).css("background-color", "yellow");
6 });
7 });
1$(".selector").on({
2 mouseenter: function () {
3 //stuff to do on mouse enter
4 },
5 mouseleave: function () {
6 //stuff to do on mouse leave
7 }
8});
9
1
2$("#p1").hover(function(){
3
4 alert("You entered p1!");
5
6 },
7
8 function(){
9
10 alert("Bye! You now leave p1!");
11
12});
13