Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:57:59
Original
1131 people have browsed it

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('对象不存在');
}
Copy after login

Or directly use native Javascript code to judge:

if(document.getElementById("id"))
{
alert('对象存在');
}
 else
{
alert('对象不存在');
} 
Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!