0 ){}" method to determine whether the div element exists."/> 0 ){}" method to determine whether the div element exists.">

Home  >  Article  >  Web Front-end  >  How to determine if there is a div in jquery

How to determine if there is a div in jquery

藏色散人
藏色散人Original
2021-01-04 09:44:582923browse

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.

How to determine if there is a div in jquery

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!

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