This article mainly introduces the usage of triggerHandler() method in jQuery. The example analyzes the function and definition of triggerHandler() method and the usage skills of triggering the specified event type of selected elements. Friends in need You can refer to the following
The examples in this article describe the usage of the triggerHandler() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method triggers the specified event type of the selected element.
It can be seen from the above definition that this method is very similar to the trigger() method in function, but there is still a huge difference. The following are the main differences:
1. This method will not trigger the browser default event.
2. This method triggers the event processing function of the first element in the jQuery object collection and does not generate event bubbling.
3. This method returns the return value of the event processing function, rather than the chainable jQuery object.
Grammar structure:
The code is as follows:
$(selector).triggerHandler(event,[param1,param2,... ])
Parameter list:
Example code:
The code is as follows:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>脚本之家</title> <style type="text/css"> p{ width:200px; height:200px; border:1px solid blue; } </style> <script type="text/ javascript " src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $( document ).ready(function(){ $("p").click(function(){ $("p").append("脚本之家"); }); $("button").click(function(){ $("p").triggerHandler("click"); }) }) </script> </head> <body> <p></p> <button>查看效果</button> </body> </html>
The above is the detailed content of Sharing experience on using triggerHandler() in jQuery. For more information, please follow other related articles on the PHP Chinese website!