Home > Web Front-end > Front-end Q&A > How to set jquery to hide the div when the mouse clicks on it

How to set jquery to hide the div when the mouse clicks on it

WBOY
Release: 2022-03-22 15:31:15
Original
2009 people have browsed it

Jquery method to set the div to be hidden when the mouse clicks on it: 1. Bind the click event to the div element and set the event processing function; 2. In the event processing function, use the hide() method to set the div to be hidden , the syntax is "div element object.hide()".

How to set jquery to hide the div when the mouse clicks on it

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to set jquery to hide the div when clicking the mouse

hide() method hides the selected element.

The syntax is:

$(selector).hide(speed,easing,callback)
Copy after login
  • speed Optional. Specifies how quickly the effect is hidden.

Possible values:

Milliseconds "slow" "fast"

  • easing Optional. Specifies the element's speed at different points in the animation. The default value is "swing".

Possible values:

"swing" - moves slowly at the beginning/end, moves fast in the middle "linear" - moves at a constant speed Tip: More available in the extension Many easing functions available.​

  • #callback Optional. The function to be executed after the hide() method is executed.

When an element is clicked, the click event occurs.

The click() method triggers a click event, or specifies a function to run when a click event occurs.

The syntax is:

Trigger the click event of the selected element:

$(selector).click()
Copy after login

Add a function to the click event:

$(selector).click(function)
Copy after login

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div").click(function(){
$("div").hide();
});
});
</script>
</head>
<body>
<div style="width:100px;height:100px;border:1px solid red;"></div>
</body>
</html>
Copy after login

Output results:

How to set jquery to hide the div when the mouse clicks on it

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to set jquery to hide the div when the mouse clicks on it. 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