JQuery: node (insert, copy, replace, delete) Operation

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> jQuery insert, copy, replace, and delete nodes </title>
<Script type = "text/javascript" src = "jquery-1.3.2.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
// Several Methods for adding nodes
// $ ("P"). append ("<B> how are you? </B> "); // append B to the 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 "); // forward B to the p element.
// $ ("P"). after ("<B> how are you? </B> "); // insert B to the p element
// $ ("<B> how are you? </B> "). insertAfter (" p "); // insert B to the end of p.
// $ ("P"). before ("<B> how are you? </B> "); // Add B before p.
// $ ("<B> how are you? </B> "). insertBefore (" p "); // insert B to the front of the p element.


// Several Methods to delete a node
// Var $ li = $ ("ul li: eq (1)"). remove (); // Delete the 2nd element nodes in the ul Node
// $ ("Ul"). append ($ li); // Add the deleted element node to the ul Element
// $ ("Ul li"). remove ("li [title! = Pineapple] "); // Delete the li element with the title attribute not equal to" pineapple "under the ul Element
// $ ("Ul li: eq (1)"). empty (); // clear the content of the 2nd li elements under the ul Node

// Copy a node
/* $ ("Ul li"). click (function (){
$ (This ). clone (true ). appendTo ("ul"); // copy the currently clicked node and append it to the ul element. When a parameter is added, copy its event.

});
*/
// Replace the node
// $ ("P"). replaceWith ("<strong> what is your favorite fruit? </Strong> ");

});
</Script>
</Head>
<Body>
<P> hello! </P>
What is your favorite fruit?
<Ul>
<Li title = "apple"> Apple </li>
<Li title = "orange"> orange </li>
<Li title = "pineapple"> pineapple </li>
</Ul>
</Body>
</Html>

Related Article

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.