Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the concealment of adjacent elements of click elements by jquery

Shulou Source: shulou.com Published: 2022-06-01 03:08:48 09月14日 Update

The main content of this article is to explain "how to click on jquery to hide adjacent elements". Friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "jquery how to click on the elements of adjacent elements hidden" bar!

Method: 1, use click () to bind the click event to the element, and set the handler function; 2, in the handler function, use next () and prev () function to get adjacent elements, and use hide () to hide the obtained elements, the syntax is "element .next (). Hide (); element .prev (). Hide ()".

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

Jquery implements click elements, and their adjacent elements are hidden

Implementation method:

Use the click () function to bind the click event to the specified element and set the handler

In the processing function, use the next () and prev () functions to get adjacent elements, and use the hide () function to hide the acquired elements

Next (): used to get the next peer element.

Prev (): used to get the previous peer element.

Implementation code:

.siblings * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } $(document) .ready (function () {$("li.start") .css ({"color": "red") "border": "2px solid red"}) $("li.start") .click (function () {$("li.start") .next () .hide (); $("li.start") .prev () .hide ();}) }) Ul (parent node) li li (adjacent element with class name "star") li element with class name "star" Li (neighboring elements with class name "star") li

Click on the li element with the class name "star" to hide its two adjacent elements

At this point, I believe you have a deeper understanding of "jquery how to achieve click element adjacent element hiding", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Elements functions handling events content peers methods class names learning practical deeper two code interest practicality practical simple operation tutorials ways more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker OPPO Reno vpn Linux