0) {//Exists}"."/> 0) {//Exists}".">
Home > Article > Web Front-end > How does jquery determine whether a node exists?
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}".
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!