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 adds and deletes elements

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces JQuery how to add elements and delete elements, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Add elements to JQuery, delete elements 1. JQuery create element method let div = $('elm')

$('elm') can create a div element with the content elm

two。 Add element 2.1. Add append (), the original $of the prepend () method (function () {let li = $('added'); $('ul') .append (li);})

The append () method adds the element to the end of the matching element, similar to appendChild () in the native JS.

Original $(function () {let li = $('added'); $('ul') .prepend (li);})

The prepend () method adds the element to the front of the matching element, similar to insertBefore () in the native JS.

When elements are added internally, a parent-child relationship is generated.

2.2. Add before (), after () methods externally

Original

$(function () {let div = $('

Added

'); $(' div') .before (div);})

The before () method adds the element before the matching element

Original $(function () {let div = $('added'); $('div') .after (div);})

The after () method adds the element after the matching element

External elements are added to generate a brotherly relationship

two。 Delete element

1.remove ()

$(function () {$('ul') .remove ();})

Remove () removes the ul element, including child nodes

2.empty ()

$(function () {$('ul') .empty ();})

Empty () clears all child nodes within the ul node, but retains the ul itself

3.html ("")

The effect of html ("") method on empty () is basically the same.

Thank you for reading this article carefully. I hope the article "how to add and delete elements in JQuery" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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