jquery adds elements to HTML-specific tags

Source: Internet
Author: User

jquery adds elements to HTML-specific tags
Wrap
HTML (String): HTML markup code string for dynamically generating elements and wrapping target elements

Example
Wrap all the paragraphs in a newly created Div

HTML code:

<p>test paragraph.</p>
jquery Code:

$ ("P"). Wrap ("<div class= ' wrap ' ></div>");
Results:

<div class= "Wrap" ><p>test paragraph.</p></div>

return value
Jquery

Parameters
Elem (Element): A DOM element used to wrap a target element

Example
Wrap each paragraph with a div with id "content"

HTML code:

<p>test paragraph.</p><div id= "content" ></div>
jquery Code:

$ ("P"). Wrap (document.getElementById (' content '));
Results:

<div id= "Content" ><p>test paragraph.</p></div><div id= "content" ></div>

Parameters
HTML (String): tml Tag code string for dynamically generating elements and wrapping target elements

Example
Wrap all the paragraphs with a generated div

HTML code:

<p>hello</p><p>cruel</p><p>world</p>
jquery Code:

$ ("P"). Wrapall ("<div></div>");
Results:

<div><p>hello</p><p>cruel</p><p>world</p></div>

Wrapinner

Parameters
HTML (String): HTML markup Code string that is used to dynamically generate elements and wrap target elements

Example
Make each child in all paragraphs bold

HTML code:

<p>hello</p><p>cruel</p><p>world</p>
jquery Code:

$ ("P"). Wrapinner ("<b></b>");
Results:

<p><b>hello</b></p><p><b>cruel</b></p><p><b>world </b></p>


Content (string, element, jquery): Used to replace a matching element

Example
Replace all the paragraph marks with the bold tags.

HTML code:

<p>hello</p><p>cruel</p><p>world</p>
jquery Code:

$ ("P"). ReplaceWith ("<b>paragraph. </b> ");
Results:

<b>paragraph. </b><b>paragraph. </b><b>paragraph. </b>

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.