Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove the Last Node by jquery

Shulou Source: shulou.com Published: 2022-05-31 19:29:34 09月15日 Update

This article mainly explains "how to remove the last node in jquery". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to remove the last node in jquery".

Remove the last node method: 1, use the "eq (- 1)" selector in the document to select the last node, syntax "$(Element:eq (- 1))"; 2, use remove () to delete the selected node, syntax "selected element .remove ()", you can delete the specified element and all internal text and child nodes.

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

Jquery removes the last node

Implementation method:

Use the ": eq ()" selector to select the last node element in the document

Delete selected node elements using remove ()

The remove () method deletes an element and everything inside it.

Key points: eq () selector

The eq () selector selects the element with the specified index value.

The index value starts at 0, so the index value of the first element is 0 (not 1).

When index is negative, select elements from back to front

Implementation code:

.div, div * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } $(document) .ready (function () {$("button") .on ("click", function () {$("li:eq (- 1)") .remove () );}) Div (parent node) ul (specified element) li (child node 1) span (grandnode 1) Li (Child Node 2) span (grandNode 2) li (Child Node 3) span (grandNode 3) Delete the last li element

Thank you for reading, the above is the content of "how to remove the last node of jquery". After the study of this article, I believe you have a deeper understanding of how to remove the last node of 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: Nodes elements selection content methods learning documents grammar code that is ideas situations tutorials texts articles more versions environment computers knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Shulou Tech Info OPPO Reno Docker