JQuery--delete/replace DOM elements

Source: Internet
Author: User

Delete

The delete operation is straightforward, and the Remove () method is called directly after the result set.

For example, to delete all the A elements in the following HTML script, go directly through the

$(‘a‘.remove();You can do it.

Of course, you can also filter the selection result by passing it to the Remove parameter, and then perform the remove operation.

$(‘a‘).remove(‘.remove‘);


It is important to note that

    1. The remove operation does not remove the eligible elements from the result set, so you can theoretically proceed with the "delete" element
    2. The remove operation will delete not only the data associated with all elements of the delete element (event handlers, internally, cached data)

Replace

If you want to replace the element you are class remove li <li>removed</li> using, you can use the following two equivalent methods

    1. $(‘li.remove‘).replaceWith(‘<li>removed</li>);
    2. $(‘<li>removed</li>;).replaceAll(‘li.remove‘);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.