How jquery determines whether a tag exists in an element

藏色散人
Release: 2022-12-30 11:13:50
Original
2817 people have browsed it

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.

How jquery determines whether a tag exists in an element

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

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

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!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!