How do I check whether a jQuery element is in the DOM?

后端 未结 11 1921
我寻月下人不归
我寻月下人不归 2020-11-28 04:46

Let\'s say that I define an element

$foo = $(\'#foo\');

and then I call

$foo.remove()

from some event. My

11条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 05:11

    jQuery.fn.isInDOM = function () {
       if (this.length == 1) {
          var element = this.get(0);
          var rect = element.getBoundingClientRect();
          if (rect.top + rect.bottom + rect.width + rect.height + rect.left + rect.right == 0)
             return false;
          return true;
       }
       return false;
    };
    

提交回复
热议问题