admin管理员组文章数量:1391999
I want something like:
$('.pac-container').whenAddToDom(function(){
console.log('element with class pac-container added to DOM');
//I want to use this added element $(this).doSomethingWithThis();
});
I want something like:
$('.pac-container').whenAddToDom(function(){
console.log('element with class pac-container added to DOM');
//I want to use this added element $(this).doSomethingWithThis();
});
Share
Improve this question
edited Jun 13, 2016 at 13:24
fico7489
asked Jun 13, 2016 at 12:46
fico7489fico7489
8,5707 gold badges59 silver badges93 bronze badges
4
- 2 Check this question. It may helpful. stackoverflow./questions/3219758/detect-changes-in-the-dom – suyesh Commented Jun 13, 2016 at 12:51
- 1 Or this question: http://stackoverflow./questions/2844565/is-there-a-javascript-jquery-dom-change-listener – Mikey Commented Jun 13, 2016 at 12:52
- Mutation Observers is what you are looking for. – Jai Commented Jun 13, 2016 at 12:54
-
1
you can listen to elements that are being appended
.bind('DOMNodeInserted DOMNodeRemoved')
– Roysh Commented Jun 13, 2016 at 13:01
2 Answers
Reset to default 4I would wrap the elements that will be appended in a container and do something like this:
$("html").bind("DOMNodeInserted",function(){
console.log('element with class '+$("#container > *").attr('class') +' added to DOM');
});
Here's a fiddle http://jsfiddle/PgAJT/295/
This is solution to my problem:
$(document).bind('DOMNodeInserted DOMNodeRemoved', function(element){
if($(this).hasClass('pac-container')){
console.log(element.target);
}
});
本文标签: javascriptJquery how to detect when some element is added to domStack Overflow
版权声明:本文标题:javascript - Jquery: how to detect when some element is added to dom? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744667343a2618612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论