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.
##jQuery Events
Here are some examples of event methods in jQuery:Event function |
Bind function to |
Example:
When you click on the button Click me, the content in thetag 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>
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 handlersThe above is the detailed content of How jquery handles events. For more information, please follow other related articles on the PHP Chinese website!