Home  >  Article  >  Web Front-end  >  How many parameters does the hover function in jquery have?

How many parameters does the hover function in jquery have?

青灯夜游
青灯夜游Original
2022-05-16 17:28:422160browse

The hover function in jquery has 2 parameters: 1. The required parameter "inFunction" is used to specify the event processing function to be run when the mouseenter event occurs; 2. The optional parameter "outFunction" is used to specify mouseleave Event handler function that runs when the event occurs.

How many parameters does the hover function in jquery have?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, the hover() method specifies two functions to be run when the mouse pointer hovers over the selected element.

This method will trigger the mouseenter and mouseleave events.

Therefore, the hover function accepts two parameters: one is required and one can be omitted.

Syntax:

$(selector).hover(inFunction,outFunction)
Parameters Description
inFunction Required. Specifies the function to run when the mouseenter event occurs.
outFunction Optional. Specifies the function to run when the mouseleave event occurs.

Note: If only one function is specified, it will run on the mouseenter and mouseleave events.

Example: Change the background color of the

element when the mouse pointer is hovering over it

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("p").hover(function() {
					$("p").css("background-color", "yellow");
				}, function() {
					$("p").css("background-color", "pink");
				});
			});
		</script>
	</head>
	<body>

		<p>鼠标移动到该段落。</p>

	</body>
</html>

How many parameters does the hover function in jquery have?

[Recommended Learning: jQuery video tutorial, web front-end video

The above is the detailed content of How many parameters does the hover function in jquery have?. 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