How to wait until an element exists?

后端 未结 19 1774
广开言路
广开言路 2020-11-22 09:14

I\'m working on an Extension in Chrome, and I\'m wondering: what\'s the best way to find out when an element comes into existence? Using plain javascript, with an interval t

19条回答
  •  醉酒成梦
    2020-11-22 09:51

    You can listen to DOMNodeInserted or DOMSubtreeModified events which fire whenever a new element is added to the DOM.

    There is also LiveQuery jQuery plugin which would detect when a new element is created:

    $("#future_element").livequery(function(){
        //element created
    });
    

提交回复
热议问题