Home >Web Front-end >JS Tutorial >jQuery trigger() method usage introduction_jquery
Introduction to the usage of jQuery’s trigger() method:
This method triggers an event of the specified type on the matched element.
It has two syntax formats, which are introduced below.
Grammar structure 1:
Parameter analysis:
1.event: required, specifies the event to be triggered by the matching element, which can be a custom event or a standard event.
2.param: optional, parameters passed to the event processing function.
Code example:
In the above code, the select event handler is registered for the text box. When the text in the text box is selected, the text inside will turn red.
When the button is clicked, the trigger() method will be used to trigger the select event on the matching element.
Grammar structure 2: