jQuery determining if element exists on page

后端 未结 3 1052
迷失自我
迷失自我 2020-12-06 16:51

How can I determine if an element exists on a page... for instance...

$(\'select[name=\"modifier_option\"]\')

If that select box exists on

3条回答
  •  借酒劲吻你
    2020-12-06 17:38

    copy/paste from here: Is there an "exists" function for jQuery?

    jQuery.fn.exists = function(){return jQuery(this).length>0;}
    
    if ($(selector).exists()) {
        // Do something
    }
    

提交回复
热议问题