Home>Article>Web Front-end> How jquery determines whether a tag exists in an element

How jquery determines whether a tag exists in an element

藏色散人
藏色散人 Original
2021-02-05 09:42:10 2836browse

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

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!

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