Finding whether the element exists in whole html page

后端 未结 2 630
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 16:52

I want to check whether an element exists in the whole page or not. Is there any way to know if the element exists in the page through jQuery?

For example:



        
2条回答
  •  青春惊慌失措
    2020-12-10 17:37

    For element IDs:

    if($('#para1').length){
      //element with id exists
    }
    

    For element class:

    if($('.para_class').length){
      //element with class exists
    }
    

提交回复
热议问题