Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How jquery removes the previous element

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of how jquery removes the previous element, the content is detailed and easy to understand, the operation is simple and quick, and has a certain reference value. I believe you will gain something after reading this article on how to remove the previous element in jquery. Let's take a look.

Method to remove the previous element: 1, use prev () to select the previous element of the specified element, syntax "$(specified element). Prev ()", will return a jquery object containing the previous element; 2, use remove () to delete the jquery object, syntax "jquery object .remove ()".

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

Jquery's method of removing the previous element

1. Use the prev () method to select the previous element of the specified element

Prev () can get the sibling element of the specified element at the next level.

Syntax:

The $(selector) .prev (filter) parameter description filter is optional. Specifies a selector expression that narrows the search for the previous sibling element.

Example: select the previous element of the li element with the class name "start"

.siblings * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } .start {color: peru } $(document) .ready (function () {$("li.start"). Prev (). Css ({"color": "red") "border": "2px solid red"}) }) Ul (parent) li (sibling) li (last sibling of the li node with the class name "start") li ( Li node named "start") li (sibling node) li (sibling node)

Select the previous element of the li element with the class name "start"

2. Delete the selected element using remove ()

The remove () method removes the selected element, including all text and child nodes. Syntax:

Selected element .remove ()

Example: delete the previous element of the li element with the class name "start" based on the previous example

.siblings * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } .start {color: peru } $(document) .ready (function () {$("li.start"). Prev (). Css ({"color": "red") "border": "2px solid red"}) $("button") .click (function () {$("li.start"). Prev (). Remove ();}) Ul (parent) li (sibling) li (last sibling of the li node with the class name "start") li ( Li node named "start") li (sibling node) li (sibling node) deletes the previous element of the li element with the class name "start"

This is the end of the article on "how jquery removes the previous element". Thank you for reading! I believe you all have a certain understanding of "how to remove the previous element of jquery". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report