Home >Web Front-end >JS Tutorial >jQuery's method for judging common states such as display and hide_jquery

jQuery's method for judging common states such as display and hide_jquery

WBOY
WBOYOriginal
2016-05-16 16:27:381204browse

The example in this article describes how jQuery determines common states such as display and hide. Share it with everyone for your reference. The specific method is as follows:

Display: show() display:block;

Hide: hide() display:none;

When switching between display and hiding, you need to determine whether it is displayed or hidden at the moment. The following methods are commonly used to determine the conditions:

1.

Copy code The code is as follows:
if(thisNode.is(':hidden')){ ......}else{.......}

2. First add a class identifier to the Dom element of thisNode, for example, change the identifier to class="showFlag", the judgment is as follows
Copy code The code is as follows:
if(thisNode.hasClass('showFlag')){...... .}else{......}

In the same way, other contents of thisNode can also be judged, such as the number of sub-elements, text content, etc., based on specific needs.

I hope this article will be helpful to everyone’s jQuery programming.

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