Home > Web Front-end > JS Tutorial > body text

How jquery handles events

(*-*)浩
Release: 2019-05-30 10:34:25
Original
3076 people have browsed it

jQuery event function jQuery event handling method is the core function in jQuery.

Event handlers refer to methods that are called when certain events occur in HTML. The term "triggered" (or "inspired") by an event is often used.

How jquery handles events

##jQuery Events

Here are some examples of event methods in jQuery:

$(document).ready(function)Bind the function to the document's ready event (when the document has finished loading)$(selector).click(function)Trigger or bind a function to the click event of the selected element$(selector ).dblclick(function)Trigger or bind the function to the double-click event of the selected element$(selector).focus( function)Trigger or bind a function to the focus event of the selected element$(selector).mouseover(function)Trigger or bind a function to the mouseover event of the selected element
Event function
Bind function to










Example:

When you click on the button Click me, the content in the

tag will be hidden.

<html>
<head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
        $("button").click(function(){
        $("p").hide();
        });
        });
    </script>
</head>

<body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click me</button>
</body>
</html>
Copy after login

Conclusion

Since jQuery is specifically designed for handling HTML events, your code will be more appropriate and easier to maintain when you follow the following principles:

Place all jQuery code in event handlers


Place all event handlers in document ready event handlers

Place jQuery code in separate .js file

Rename the jQuery library if there is a name conflict

The above is the detailed content of How jquery handles events. 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