Home  >  Article  >  How to use jQuery hover() method

How to use jQuery hover() method

小老鼠
小老鼠Original
2023-12-04 09:56:28902browse

hover() is a commonly used method in jQuery. It is used to bind two event handling functions. These two functions will be executed when the mouse pointer enters and leaves the matching element. The basic usage method is "$(selector).hover(inFunction,outFunction);".

How to use jQuery hover() method

hover() is a commonly used method in jQuery. It is used to bind two event handling functions. These two functions will be used when the mouse pointer enters and Executed when leaving the matched element. Basically, it's shorthand for mouseenter and mouseleave events.

The basic usage is as follows:

$(selector).hover(inFunction,outFunction);

Among them:

inFunction is the function executed when the mouse pointer enters the matching element.

outFunction is the function executed when the mouse pointer leaves the matching element.

For example, suppose you want to change the background color of a

element when the mouse pointer enters it, and restore the background color when the mouse pointer leaves it, you would do this:

$("div").hover(function(){  
   $(this).css("background-color", "yellow");  
}, function(){  
   $(this).css("background-color", "white");  
});

In this In the example, inFunction changes the background color of

to yellow, and outFunction changes it back to white. The inFunction is fired when the mouse pointer enters the
, and the outFunction is fired when the mouse pointer leaves the
.

The above is the detailed content of How to use jQuery hover() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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