JS Event Registration Failure issue

Source: Internet
Author: User

Yesterday, the development of the time has been tangled up a problem, to a tag registration event, but has not been registered!

$ (' #myTab li a '). Click (function () {Localstorage.setitem (TabId, $ (this). attr ("href"));

is completely an ordinary event registration code. Today's troubleshooting concludes that the $ (' #myTab li a ') element is Ajax-loaded asynchronously. And I register the event immediately after the AJAX code call is complete. So the problem is, the AJAX code is executed asynchronously, the code is called out, it doesn't mean that the element that needs to bind the event is loaded. If an element has not yet been loaded, the binding event is futile !

The solution is to bind the event in the success method of the Ajax call.

Planted in this pit several time, record, after the hearts.

JS Event Registration Failure issue

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.