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.