Get the App
SLTechnology News&Howtos  ›  Development  › 

How to click on the display element and click on the hidden element again in jquery

Shulou Source: shulou.com Published: 2022-06-02 12:11:17 09月25日 Update

This article mainly explains "jquery how to click on the display element and click on the hidden element again". The content in the article is simple and clear, and it is easy to learn and understand. below, please follow the editor's train of thought slowly and deeply, together to study and learn "jquery how to click on the display element and click on the hidden element again"!

Methods: 1, use the click () method to bind the click event to the button and specify the handler function; 2, in the function with if statement, show () and hide () to achieve, the syntax "if (element object .is (': hidden')) {element object .show ();} else {element object .hide ();}".

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

How to click on the display element and click on the hidden element again in jquery

In jquery, you can click the button to show and click to hide again through the show () method and the hide () method, and the hide () method hides the selected element if it is already displayed. The syntax is:

$(selector) .hide (speed,callback)

The show () method displays selected elements if they are hidden. The syntax is:

$(selector) .show (speed,callback)

Let's take a look at how to achieve county-level display and click hide again through an example, as shown below:

Div {width:100px;height:100px;background: red;} Show and hide $(function () {('# anniu') .click (function () {/ / Click the button if ($('# test'). Is (': hidden')) {/ / if currently hidden $('# test'). Show (); / / Click to show} else {/ / otherwise $('# test'). Hide (); / / Click to hide}})

Output result:

Thank you for your reading, the above is the content of "jquery how to click on the display element and click on the hidden element again". After the study of this article, I believe you have a deeper understanding of how to click on the display element and click on the hidden element again in jquery, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Elements again methods objects buttons syntax learning content functions examples usage events can be passed that is ideas situations tutorials articles more versions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker macOS vpn NVidia