What is the method to set click event in jquery

WBOY
Release: 2022-05-10 11:27:47
Original
3873 people have browsed it

The method for setting click events in jquery is click(); this method is used to set a click event to occur when an element is clicked. When the mouse pointer stays over the element and the left button is clicked, the click event will be triggered or Specifies the function to be run when a click event occurs. The syntax is "element object.click (run function)".

What is the method to set click event in jquery

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

What is the method for setting click events in jquery?

The method for clicking events in jquery is click() method

When the element is clicked , a click event occurs.

A click occurs when the mouse pointer stays over an element, and then the left mouse button is pressed and released.

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

Trigger click event

$(selector).click()
Copy after login

Bind function to click event

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

function Optional. Specifies a function to run when a click event occurs.

The example is as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("p").slideToggle();
  });
  $("p").dblclick(function(){
    $("button").click();
  });
});
</script>
</head>
<body>
<button>点击这里进行切换</button>
<p>双击本段落会触发上面这个按钮的 click 事件。</p>
</body>
</html>
Copy after login

Output result:

What is the method to set click event in jquery

##Related video tutorial recommendation:

jQuery video tutorial

The above is the detailed content of What is the method to set click event in jquery. 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