Home  >  Article  >  Web Front-end  >  What should I do if the jquery trigger function cannot trigger the a tag?

What should I do if the jquery trigger function cannot trigger the a tag?

php中世界最好的语言
php中世界最好的语言Original
2018-03-15 11:13:172050browse

This time I will bring you jquery triggerfunctionHow to deal with the inability to trigger the a tag, and how to handle the jquery trigger function that cannot trigger the a tagNotesYes Which ones, the following are practical cases, let’s take a look.

Cause: After clicking the icon icon, the link jump action of the a tag is triggered, but using JQ's $('#a').trigger('click') does not work. According to Baidu, the two methods are summarized as follows:

(Reason: JQ’s trigger() method cannot trigger the jump action of the a tag.)

1: JQ method:

Add a span tag inside the target a tag, and then bind trigger('click') to the span tag Event.

$('#a').html('').children().trigger('click');

(Reason: JQ The trigger function also supports bubbling)

(If there is something in the a tag, you can use appendTo() and other functions to append the tag)

2: JQ+JS method: (Recommended)

Convert $('#a') to a JS object, and then trigger the click event.

$('#a')[0].click();

Summary: I personally feel that the second method is simple and convenient, and it is recommended to use it.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

JQuery check box selection and get the value

JQuery operates the position of tr in the table

The above is the detailed content of What should I do if the jquery trigger function cannot trigger the a tag?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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