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

How to determine if there is a div in jquery

藏色散人
Release: 2023-01-04 09:38:30
Original
2997 people have browsed it

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
}
Copy after login

2. Use jquery to determine whether the div element exists.

if ($("#div").length > 0){ 
// 找到对应id=div的元素,然后执行此块代码 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template