jquery -- a problem with trigger triggering a execution event

When I needed to trigger the click event of the a tag in a recent project, I encountered a little problem. I take it for granted that the layer is written like this: $("a").trigger('click'). However, it has not been able to trigger successfully.

 

Then I asked the powerful Du Niang.

turn out to be:

$('a').trigger('click') does not trigger the click event of the content in the a tag, but is equivalent to triggering the onclick of a itself, not an event like a user click.

 

If you need to trigger the user's click event, you need to use the trigger to trigger the click event of the content in the a tag, as follows:

// The page elements are as follows

Click me to open Baidu

// trigger event as follows

$('a span').trigger('click');

 

Note: The trigger event must be bound to the span in the a tag

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325128371&siteId=291194637