Home > Web Front-end > JS Tutorial > body text

What are jQuery mouse events?

一个新手
Release: 2017-09-11 10:27:52
Original
1831 people have browsed it

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(){});
Copy after login

Example:

$('p').click(function(){
        alert('click function is running !');
       });
Copy after login

2. dbclick event : Triggered when two clicks occur in quick succession

 $('p').dbclick(function(){});

Example:

$("button").dblclick(function(){
 $("p").slideToggle();
});
Copy after login

3, mousedown event: Triggered when the mouse is pressed

 $('p').mousedown(function(){});

Example

$("button").mousedown(function(){
 $("p").slideToggle();
});
Copy after login

4. Mouseup event: Triggered when the mouse is released

 $('p').mouseup(function(){});

Example:

$("button").mouseup(function(){
 $("p").slideToggle();
});
Copy after login

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(){});
Copy after login

Example:

$("p").mouseover(function(){
 $("p").css("background-color","yellow");
});
$("p").mouseout(function(){
 $("p").css("background-color","#E9E9E4");
});
Copy after login

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(){});
Copy after login

Example

$("p").mouseenter(function(){
 $("p").css("background-color","yellow");
});
$("p").mouseleave(function(){
 $("p").css("background-color","#E9E9E4");
});
Copy after login

7, hover event

 $('p').hover(
    function(){},
    function(){}
  );
Copy after login

Example

$(".table_list tr").hover( 
function () { 
$(this).addClass("hover"); 
}, 
function () { 
$(this).removeClass("hover"); 
} 
);
Copy after login

8, toggle event: mouse click switching event

 $('p').toggle(
    function(){},
    function(){}
  );
Copy after login

Example

$("p").toggle(
 function(){
 $("body").css("background-color","green");},
 function(){
 $("body").css("background-color","red");},
 function(){
 $("body").css("background-color","yellow");}
);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!