Check if a DIV id exists with JQuery

前端 未结 2 1295
执笔经年
执笔经年 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:03

    Your case is incorrect in your sample code. You should be invoking getElementById, with a lowercase d. Javascript is case sensitive.

    If you're using jquery, make sure to prefix id with a #, like so $("#test_div"), so jquery knows you want to query for an element id.

提交回复
热议问题