How can I detect when a new element has been added to the document in jquery?

前端 未结 10 1380
猫巷女王i
猫巷女王i 2020-12-01 21:29

How can I detect when a new element has been added to the document in jquery ?

Explanation: I want to know when an element with class \"column-header\" has been adde

10条回答
  •  心在旅途
    2020-12-01 22:03

    I would use setInterval to repeatedly check for element. eg.

    var curLength=0;
    setInterval(function(){
      if ($('.column-header').length!=curLength){
        curLength=$('.column-header').length;
        // do stuff here
      }
    },100);
    

    this code will check for any new .colum-header elements every 100 ms

提交回复
热议问题