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

How to determine whether jquery div is empty

藏色散人
藏色散人Original
2021-01-25 09:54:422483browse

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();
}

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>

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!

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