Jquery method to determine whether there is a div: 1. Use "if(document.getElementById('div')) {}" to determine whether the div element exists; 2. Use "if ($("#div ").length>0){}" method to determine whether the div element exists.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
Recommended: "javascript basic tutorial""jquery video tutorial"
jquery determines whether there is a div element
1. Use javascript to determine whether the div element exists.
if(document.getElementById('div')) { //code } else { //code }
2. Use jquery to determine whether the div element exists.
if ($("#div").length > 0){ // 找到对应id=div的元素,然后执行此块代码 }
For more programming-related knowledge, please visit: Programming Teaching ! !
The above is the detailed content of How to determine if there is a div in jquery. For more information, please follow other related articles on the PHP Chinese website!