Comparison between jQuery and JavaScript node Insert elements

Source: Internet
Author: User
Comparison between jQuery and JavaScript node Insert elements 2. Insert elements:

Face the sea, spring flowers bloom

(1) jQuery Method

1. Insert in the node:

The specific implementation is as follows:

$ ("P"). append ("

This is the content added by the append () method.

"); // Insert a section at the first subnode under the p element $ (" p "). prepend ("

This is the content added by the prepend () method.

"); // Insert a paragraph at the position of the last subnode under the p element

The following two methods are more in line with people's general thinking, but the results are the same

$ ("

This is the content added by the appendTo method.

"). AppendTo (" p "); // insert a paragraph to the first subnode position of the p element $ ("

This is the content added by the prependTo method.

"). PrependTo (" p "); // inserts a paragraph into the last subnode of the p element.

The specific implementation is as follows:

$ ("P"). after ("

This is the content added by the after () method.

"); // Insert a paragraph after the p element $ (" p "). before ("

This is the content added by the before () method.

"); // Insert a paragraph before the p element

$ ("P"). after ("

This is the content added by the after () method.

"); // Insert a paragraph after the p element $ (" p "). before ("

This is the content added by the before () method.

"); // Insert a paragraph before the p element

(2) JavaScript Method

1. Insert in the node: appendChild () --- corresponding to jQuery's append (), insertBefore () --- corresponding to jQuery's prepend ()

For more information, see the jQuery method above...

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.