admin管理员组文章数量:1278789
I know of and research multiple ways to bind events .on()
, .live()
, .click()
, etc. I know .live()
is deprecated in 1.9+. The problem I'm encountering is binding dynamic DOM elements to events.
I have a div
that contains links and is paginated. The links are dynamically loaded with AJAX. I want to overwrite binded events for these links so I used .unbind()
and tried .on()
. The problem is that these dynamically loaded links are not binded. I guess that's because the selector $('#id_of_links')
is cached with the previous set of links.
QUESTION: Is it possible to bind all elements that are loaded on the page, at any point in time, without having to set a callback when the user clicks next page on the links?
I know of and research multiple ways to bind events .on()
, .live()
, .click()
, etc. I know .live()
is deprecated in 1.9+. The problem I'm encountering is binding dynamic DOM elements to events.
I have a div
that contains links and is paginated. The links are dynamically loaded with AJAX. I want to overwrite binded events for these links so I used .unbind()
and tried .on()
. The problem is that these dynamically loaded links are not binded. I guess that's because the selector $('#id_of_links')
is cached with the previous set of links.
QUESTION: Is it possible to bind all elements that are loaded on the page, at any point in time, without having to set a callback when the user clicks next page on the links?
Share Improve this question asked Jun 3, 2013 at 13:47 Eric KimEric Kim 2564 silver badges9 bronze badges 02 Answers
Reset to default 15for dynamically added elements, you must bind the function to one of it's parents
$('#PARENT').on('click', '#DYNAMICALLY_ADDED_CHILD', function(){ CODE HERE });
Parent should already exist in the DOM tree...
More info on: http://api.jquery./on/
You cannot bind all elements, even those not loaded in the page yet, without having a callback method/function or a function that would loop in and keep checking if the elements with a specific attribute or characteristic would have the proper function binded to it, which would probably cause a memory leak over time.
本文标签: javascriptjQuery event binding with dynamically loaded elementsStack Overflow
版权声明:本文标题:javascript - jQuery event binding with dynamically loaded elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741234461a2362731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论