Home >Web Front-end >JS Tutorial >jQuery method to determine whether the object with the specified id exists_jquery

jQuery method to determine whether the object with the specified id exists_jquery

WBOY
WBOYOriginal
2016-05-16 15:57:591185browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn