Check if a DIV id exists with JQuery

前端 未结 2 1281
执笔经年
执笔经年 2021-02-18 22:48

Using Javascript I\'m trying to test whether or not a DIV with the id \"test_div\" exists in the document.

I\'m using

if (getElementById(\"test_div\"))
<         


        
2条回答
  •  梦如初夏
    2021-02-18 23:16

    You would have to do document.getElementById(id). But seeing how you are using jquery - you could also do $(id).length > 0 to check if the element exists

提交回复
热议问题