How to check if an object with an ID already exists on the page?

Possible Duplicate:
Is there an “exists” function for jQuery

Say for instance you have the div:

<div id="hello"></div>

And you are dynamically creating a div:

<div id="hello"></div>

Is there a function you can use in Jquery which will check to see if the object with the ID you are trying to create already exists on the page?


对于jQuery方法,你可以一起去

if($("#selector").length) {
    //object already exists
}

if (document.getElementById('hello')) {
    // yup, already there
}

或者,jQuery的方式:

if ($('#hello').length) {
    // yup, already there
}
链接地址: http://www.djcxy.com/p/14676.html

上一篇: 检查是否存在具有相同类的多个元素

下一篇: 如何检查页面上是否存在具有ID的对象?