Finding whether the element exists in whole html page

后端 未结 2 628
没有蜡笔的小新
没有蜡笔的小新 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:39

    recently I faced the same problem & this is good for me.

    if ( $('#para1').lenght == 1 ){ // if the id exists its length will be 1 
    
          alert('This Id exists');
    
    } elseif ( $('#para1').lenght == 0 ){ // if the id doesn't exists its length will be 0
    
          alert('This Id does not exists');
    }
    

提交回复
热议问题