Home > Web Front-end > JS Tutorial > How to determine whether jquery div is empty

How to determine whether jquery div is empty

藏色散人
Release: 2022-12-30 11:12:32
Original
2547 people have browsed it

How to determine whether jquery div is empty: first introduce jQuery.min.js into the html page; then introduce jQuery and searchNull.js; finally add the id attribute to any div in the html page as " no_content" can realize the judgment.

How to determine whether jquery div is empty

The operating environment of this tutorial: windows7 system, jquery1.2.6 version, DELL G3 computer.

Recommended: jquery video tutorial

How to use jQuery to determine whether a div is empty

1. In the html page Introduce jQuery.min.js, it is best to use version 1.2 or above

2. The searchNull.js code is as follows

function validate() {
   //var content = $("#content").html();
   var noContent = $("#no_content").html();
   // if (content == null || content.length == 0) {
   //     alert("content:" + conten);
   // }
   if (noContent == null || noContent.length == 0) {
      $("#no_content").append("<p>对不起,没有相关的查询结果</p>");
      alert("对不起,没有相关的查询结果");
       window.location.href=&#39;/Shop&#39;;
   }
}
 
window.onload = function () {
validate();
}
Copy after login

3. The usage is as follows

First introduce jQuery and searchNull .js

Add the id attribute to no_content on any div in the html page

Example:

<div id="no_content">
</div>
Copy after login

The above is the detailed content of How to determine whether jquery div is empty. 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