jquery-replacing and deleting elements

Source: Internet
Author: User

1. ReplaceWith method
Replaces all matching elements in the collection with the provided content and returns the collection of substituted elements
Parameter type description:
1) Normal string (can contain various HTML tags)
2) JQuery Object
① new element created with the $ function (jquery object)
② using the $ function to get the elements already in the page (jquery objects)
The existing elements are moved to the new location
③ using the Clone method to clone an existing element in a page (jquery object)
3) HTML element object, HTML element object array
4) function
How many matches are there, and how many times this function executes!
The function can accept two parameters: the first is the ordinal of the current element, and the second is the HTML within the current element.
Inside the function this represents the current HTML element object
The return data is the replacement content (can be HTML elements, or jquery objects)
2. ReplaceAll method
Replace each target element with a matching element of the collection (same as ReplaceWith)
Differences from Replacewitch:
Target and Source opposite
Creates a new element that returns the JQuery object associated with the
This method can be called by a jquery object that has elements returned from the selected page (selecting an existing element in the page means moving an existing element to the target element)!
Parameter (indicates the target location to insert the element):
Selector or jquery object or HTML element object/html element Object array

3. Detach () method
Removes the matched element from the page and returns the call to the element jquery object
Parameter description:
(optional) A selector filters the elements that need to be removed from the matching elements
4. Empty () method
Removes all descendant elements (including text) of a matching element from the page
5. Remove () method
Removes the matching element collection from the page, returning the call to the element jquery object (while removing the event handler and associated data on the element)
If you delete an element, you do not need to delete the associated data and events, use Detach ()
Parameter description:
(optional) A selector to filter the collection of matched elements to be removed
6. Unwrap () method
Deletes the parent element of the matching element collection, preserving itself (and the sibling element, if present) in its original position

jquery-replacing and deleting elements

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.