After AJAX update data, jquery, JQ failure problem _jquery

Source: Internet
Author: User
Bind the Click event to an element, but one problem is that the Click event fails when I execute some AJAX requests

For example, my paging is an AJAX request, but when I click on the next page, the resulting element A does not have the Click event.

But the reason is simple.

Ajax loading content is after the $ (document). Ready () operation, this time to the binding function, the found element set does not include Ajax loaded content, so the original no problem, after loading is not bound

There are two solutions:

1. rebind after the AJAX request succeeds
2. Live method
Copy Code code as follows:

<script type= "Text/javascript" >
<!--
JQuery (document). Ready (function () {
JQuery (". Brand Li img"). Live (' click ', function () {

JQuery (This). Parents ("Li"). Find ("ul"). Slidetoggle ();
});
});
-->
</script>

Two methods apply in different situations

If you're dealing with an event, you can use live
If it's some other way, live doesn't support only rebind.
Related Article

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.