First, JQuery-adding elements
1.append ()-Inserts the specified content at the end of the selected element
2.prepend ()-Inserts the specified content at the beginning of the selected element
3.after ()-Insert content after selected element
4.before ()-Insert content before selected element
Add a single element
<script type= "Text/javascript" src= "Jquery-1.11.2.min.js" ></script><body><p>111</p ></body>$ (document). Ready (function (e) {$ ("P"). Append ("222"); $ ("P"). Prepend ("333"); $ ("P"). After ("444"); $ ("P"). Before ("555");}); </script>
Add several elements---- Focus
<body><button onclick= "Tianjia ()" > Append text </button></body>functionTianjia () {vartxt1= "<p> text 1</p>";//Create text using HTML tags vartxt2=$ ("<p></p>"). Text ("Text 2");//Create text using JQuery varTxt3=document.createelement ("P"); Txt3. innerhtml= "Text 3";//using the DOM to create text with Dom$ ("Body"). Append (TXT1,TXT2,TXT3);//Append new Element}</script>
Ii. JQuery-Delete Element
1.remove ()-delete the selected element (and its child elements)
2.empty ()- removes child elements from the selected element
<div id= "Div1" >111111<p>2222222</p><pclass= "PP" >3333333333</p><pclass= "pp" >444444444</p></div><br><button> remove div element </button></body>$ (document). Ready (function(){ $("button"). Click (function(){ $("#div1"). Remove ();//Delete div and all the contents of P inside it $("#div1").Empty();//Delete the contents of the P tag inside the Div $("P"). Remove (". pp");//Remove all P labels that are class pp });});</script>
jquery Add, remove elements