Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery deletes the previous element

Shulou Source: shulou.com Published: 2022-06-02 14:47:48 10月04日 Update

Editor to share with you how jquery deleted the previous element, I hope you will learn something after reading this article. Let's discuss it together.

Jquery method to delete the previous element: 1, use the prev () method to get the previous element object of the specified element, syntax "$(selector). Prev ()"; 2, use the remove () method to delete the previous element object, syntax "previous element object .remove ()".

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

Jquery deletes the previous element

In jquery, to delete the previous element, you first need to get the previous element, which requires the use of the prev () method.

The prev () method returns the previous sibling of the selected element. (sibling elements are elements that share the same parent element. )

When you get the previous element, you need to delete it using the remove () method.

Implementation code:

$(document) .ready (function () {$("# but1") .click (function () {$("# box"). Prev (). Remove ();}))

The first paragraph

The second paragraph

The third paragraph

Paragraph 4-# box element

The fifth paragraph

The sixth paragraph

Delete the previous element of # box element

After reading this article, I believe you have a certain understanding of "how to delete the previous element of jquery". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Elements methods objects siblings articles grammars same code six paragraphs done tutorials more versions environment computers knowledge systems industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL vpn Microsoft MariaDB