Jquery method to determine whether a dom element exists: 1. Use the "$("#id")" statement to obtain the dom element object through the id attribute; 2. Use the "element object.length" statement to obtain the length value; 3. Determine whether the obtained length value is greater than 0. If it is greater, it exists, otherwise it does not exist.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery determines whether the dom element exists
Implementation idea:
Pass in the js file The id attribute gets the dom element object
Use the length attribute to get the length of the dom element object, If the element exists, length=1
Determine whether the length value is greater than 0
if($("#id").length >0){ //元素存在,则length=1 alert("元素存在"); }else{ //元素不存在,则length=0 alert("元素不存在"); }
jQuery tutorial (video)
The above is the detailed content of How does jquery determine whether a dom element exists?. For more information, please follow other related articles on the PHP Chinese website!