jquery trigger <a> Tag's Click event is invalid

Source: Internet
Author: User

1     <a id= "Workframe" href= "pages/work.html" target= "Framebox" > Home </a>  2       
3 $ ("#workFrame"). Tigger ("click");

The above code, in fact, is quite normal, but how can not trigger the A-tag click event. Baidu for a moment, the solution is as follows

1     <a id= "Workframe" href= "pages/work.html" target= "Framebox" ><span id= "Aspan" > Home </span></a>  23      $ ("#aSpan"). Tigger ("click");  

Of course there is a problem here, that is, why the click event triggering a SPAN will trigger the Click event of a tag, which is an event bubbling process

1, the event source triggers the onclick event, and then its parent element also triggers the Click event, after which its grandparent element then triggers the click event until the HTML element (the standard and support events bubble, also supports event capture, event capture is the opposite of event bubbling, from HTML to the event source, Of course, our great ie in principle can not be associated with it, have their own style, only support event bubbling)

2, of course, can also prevent event propagation

• Using the Stoppropagation () method in the

• Set cancelbubble = True under IE;
3, you can also block the default behavior, such as Click <a> Jump ~
• Use the Preventdefault () method in the user's list;
• Set window.event.returnValue = False under IE;

On the specific content of event propagation: former focus on http://www.jb51.net/article/42492.htm

jquery trigger <a> Tag's Click event is invalid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.