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

How does jquery determine whether a node exists?

青灯夜游
Release: 2020-11-19 16:38:42
Original
3946 people have browsed it

Jquery method to determine whether a node exists: first use the length attribute to get the number of elements in the node object; then determine whether the number of elements obtained is greater than 0. If it is greater than 0, the node exists, otherwise it does not exist; syntax format " if ($(selector).length>0) {//Exists}".

How does jquery determine whether a node exists?

Related recommendations: "jQuery Video"

jquery determines whether a node exists

jquery

if ($("#map").length > 0) {
        console.log("true");
    } else {
        console.log("false");
    }
Copy after login

Supplement:js

if (document.getElementById("map")) {
        console.log("存在");
        console.log(document.getElementById("map"));
    } else {
        console.log("不存在");
        console.log(document.getElementById("map"));
    }
Copy after login

if (!!document.getElementById("map")) {
        console.log("true");
    } else {
        console.log("false");
    }
Copy after login

For more programming-related knowledge, please visit: Programming Learning Course! !

The above is the detailed content of How does jquery determine whether a node exists?. For more information, please follow other related articles on the PHP Chinese website!

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