Home > Web Front-end > JS Tutorial > Determination code in JQuery to determine whether there is content or a certain tag under an element_jquery

Determination code in JQuery to determine whether there is content or a certain tag under an element_jquery

WBOY
Release: 2016-05-16 17:56:55
Original
1015 people have browsed it

1. Determine whether the text is empty

Copy the code The code is as follows:

var jqObj = $( this);
if(jqObj.text().trim()){ //trim() method is to remove spaces, $.trim() function removes all line breaks and spaces (including non-breaking spaces) in the provided string ), start and end tab. If these whitespace characters occur in the middle of the string, they will be preserved.
jqObj.hide();
}

2. Determine whether there is a known element under this tag, such as determining whether there is a li element under the ul tag
Copy code The code is as follows:

var jqObj = $(this);
if(!jqObj. has('li').length){
jqObj.hide();
}
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