Home>Article>Web Front-end> How jquery determines whether a tag exists in an element
The method to determine whether a tag exists in an element in jquery: first obtain the element object; then use the "has('label object').length" method to determine whether a certain tag exists.
The operating environment of this article: Windows7 system, jquery1.2.6, Dell G3 computer.
jquery determines whether there is content or a certain tag in an element?
1. Determine whether the text is empty
var jqObj = $(this); if(jqObj.text().trim()){ //trim()方法是去空格,$.trim()函数删除提供字符串的所有换行符,空格(包括非中断空格),开始和结束tab。如果这些空白字符在字符串中间发生时,它们将被保留。 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
var jqObj = $(this); if(!jqObj.has('li').length){ jqObj.hide(); }
Recommendation: "jquery video tutorial"
The above is the detailed content of How jquery determines whether a tag exists in an element. For more information, please follow other related articles on the PHP Chinese website!