Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery checks whether elements are hidden

Shulou Source: shulou.com Published: 2022-06-01 11:15:26 10月15日 Update

This article focuses on "jquery how to check whether elements are hidden", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "jquery how to check whether elements are hidden"!

Jquery check whether the element is hidden methods: 1, the use of is () method and ": hidden" selector, syntax "element object. Is (": hidden ")"; 2, the use of is () method and ": visible" selector, syntax "element object .is (": visible ")".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery checks whether the element is hidden

1. Using is () method and ": hidden" selector

$(document) .ready (function () {$("button") .click (function () {if ($("# hide"). Is (": hidden")) {console.log ("# hide element is hidden") } else {console.log ("# hide element is not hidden, it is visible") } if ($("# show") .is (": hidden") {console.log ("# show element is hidden") } else {console.log ("# show element is not hidden, it is visible");});}) # hide element-I am hidden content, you can't see me. # show element-I am the content displayed, you can see me.

Check whether the element is hidden

2. Using is () method and ": visible" selector

$(document) .ready (function () {$("button") .click (function () {if ($("# hide") .is (": visible")) {console.log ("# hide element is not hidden, is visible") } else {console.log ("# show element is hidden");});})

The running result is the same as the figure above.

Description:

Visibility filter selector:

$("div:hidden") selects all invisible elements

$("div:visible") selects all visible elements

The is () method is used to see if the selected element matches the selector.

At this point, I believe you have a deeper understanding of "jquery how to check whether the element is hidden". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Elements methods selection check content objects grammar learning practical deeper above interest practicality practical easy to operate tutorials more friends versions environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux OPPO Reno Xiaomi Microsoft