Home >Web Front-end >JS Tutorial >What are jQuery mouse events?
Mouse events are triggered when the user moves the mouse cursor or clicks with any mouse button.
1. Click event : Triggered when the left mouse button is clicked
$('p').click(function(){});
Example:
$('p').click(function(){ alert('click function is running !'); });
2. dbclick event : Triggered when two clicks occur in quick succession
$('p').dbclick(function(){});
Example:
$("button").dblclick(function(){ $("p").slideToggle(); });
3, mousedown event: Triggered when the mouse is pressed
$('p').mousedown(function(){});
Example
$("button").mousedown(function(){ $("p").slideToggle(); });
4. Mouseup event: Triggered when the mouse is released
$('p').mouseup(function(){});
Example:
$("button").mouseup(function(){ $("p").slideToggle(); });
5. Mouseover event: Triggered when the mouse moves from one element into another element
mouseout event: Triggered when the mouse moves out of the element
$('p').mouseover(function(){}); $('p').mouseout(function(){});
Example:
$("p").mouseover(function(){ $("p").css("background-color","yellow"); }); $("p").mouseout(function(){ $("p").css("background-color","#E9E9E4"); });
6. mouseenter event: Triggered when the mouse moves into the element
mouseleave event: Triggered when the mouse moves out of the element
$('p').mouseenter(function(){}); $('p').mouseleave(function(){});
Example
$("p").mouseenter(function(){ $("p").css("background-color","yellow"); }); $("p").mouseleave(function(){ $("p").css("background-color","#E9E9E4"); });
7, hover event
$('p').hover( function(){}, function(){} );
Example
$(".table_list tr").hover( function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); } );
8, toggle event: mouse click switching event
$('p').toggle( function(){}, function(){} );
Example
$("p").toggle( function(){ $("body").css("background-color","green");}, function(){ $("body").css("background-color","red");}, function(){ $("body").css("background-color","yellow");} );
The above is the detailed content of What are jQuery mouse events?. For more information, please follow other related articles on the PHP Chinese website!