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...