How to check htmlElement object exists in DOM

This question already has an answer here:

  • Is there an “exists” function for jQuery? 36 answers

  • 您可以检查DOM是否包含htmlElement

    if ($.contains(document, $(htmlElement)){
        // htmlElement is attached to the DOM
    }
    

    In order to give proper condition you always need to check length of object

    ie if($("li.k-button.k-state-hover").length)


    试用javascript:

    var ele =  document.getElementById('yourId');
    
     or
    
    var ele = document.getElementByTagName('tag name');
    
    if (typeof(ele) != 'undefined' && ele != null)
    {
      // exists.
    }
    
    链接地址: http://www.djcxy.com/p/14694.html

    上一篇: 按值设置选择选项'selected'

    下一篇: 如何在DOM中检查htmlElement对象