Home >Web Front-end >JS Tutorial >How to use the click() method in jQuery

How to use the click() method in jQuery

不言
不言Original
2018-12-27 16:06:118951browse

The click() method in How to use the click() method in How to use the click() method in jQuery is often used for events that occur when clicking buttons, so in this article we will introduce the specific usage of click() in How to use the click() method in How to use the click() method in jQuery.

How to use the click() method in How to use the click() method in jQuery

Let’s first take a look at what the click() method is?

jquery methods are usually written with the following functions.

$(function(){
  //处理的内容 
});

However, with this program, since the code is executed (also called triggered) when the page is reloaded, the purpose of dynamically changing the page cannot be achieved, which is the original purpose of How to use the click() method in How to use the click() method in jQuery.

For this reason, How to use the click() method in How to use the click() method in jQuery provides a way to specify when to fire. The click method creates a process that is called when the specified button is pressed.

BelowWe write the click method

$(function(){
  $(“选择器”).click(function(){
    //处理的内容
  });
});

After using the selector to specify the button, call the click method.

Use the parameters of the click method to call the function and execute the content of the function.

Let’s look at a specific example

When you click the button, the letters will become larger

The code is as follows

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script>
      $(function() {
        $("button").click(function() {
          $(".big").css("font-size", "50px");
        });
      });
    </script>
  </head>
  <body>
   <button>button</button>
   <p class="big">big</p>
  </body>
</html>

Use the selector to specify the button and Use css method to increase font size.

The running results are as follows

How to use the click() method in How to use the click() method in jQuery

When the button is clicked, the letters below will become larger

How to use the click() method in How to use the click() method in jQuery

This article ends here. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website for further study! ! !

The above is the detailed content of How to use the click() method in jQuery. 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