0) {//Exists}"."/> 0) {//Exists}".">

Home >Web Front-end >JS Tutorial >How does jquery determine whether a node exists?

How does jquery determine whether a node exists?

青灯夜游
青灯夜游Original
2020-11-19 16:38:423975browse

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");
    }

Supplement:js

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

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

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!

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