Jquery Add node

Source: Internet
Author: User

$ (document). Ready (function () {
Several ways to add nodes
$ ("P"). Append ("<b> How are you? </b>);//Add "B" to P element
$ ("<b> how are you? </b> "). AppendTo (" P ");//append" B "to the P element
$ ("P"). Prepend ("<b> How are you? </b>);//forward "B" to P
$ ("<b> how are you? </b> "). Prependto (" P ");//place" B "before the P element
$ ("P"). After ("<b> How are you? </b> ");//insert" B "after P element
$ ("<b> how are you? </b> "). InsertAfter (" P ");//insert" B "behind the P element
$ ("P"). Before ("<b> How are you? </b>);//Add "B" before the P element
$ ("<b> how are you? </b> "). InsertBefore (" P ");//insert" B "in front of P element


Several ways to delete nodes
var $li =$ ("ul li:eq (1)"). Remove ();//delete the 2nd element node in the UL node
$ ("ul"). Append ($li);//Add the newly deleted element node to the UL element
$ ("ul Li"). Remove ("li[title!= pineapple");//Remove the LI element under the title attribute of the UL element not equal to "pineapple"
$ ("ul Li:eq (1)"). empty ();//Empty the contents of the 2nd Li element under the UL node

Replication nodes
/* $ ("ul Li"). Click (function () {
$ (this). Clone (True). AppendTo ("ul");//Copy the currently clicked node and append it to the "ul" element, copying its event when adding a parameter

});
*/
Replace node
$ ("P"). ReplaceWith ("<strong> Your least favorite fruit? </Strong> ");



});

Jquery Add node

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.