Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:56:55937browse

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