Home >Web Front-end >JS Tutorial >jQuery method to determine whether the object with the specified id exists_jquery
jQuery determines whether the object with the specified id exists. It only needs to determine whether the length of the object is greater than 0.
Example:
The correct way to write the judgment is as follows:
if($("#object_id").length>0) { alert('对象存在'); } else { alert('对象不存在'); }
Or directly use native Javascript code to judge:
if(document.getElementById("id")) { alert('对象存在'); } else { alert('对象不存在'); }
The above is the entire content of this article, I hope you all like it.