First, create a node
In order to make the page more intelligent, sometimes we want to dynamically add an element tag on the HTML structure page, then the first thing to do before inserting is: Create the node
<Scripttype= "Text/javascript"src= "Jquery-1.12.3.min.js"></Script><Script>$(function(){ varBox= $('<div id= "box" > Nodes </div>'); //Create a node $('Body'). append (box); //inserting a node inside a <body> element});</Script></Head><Body> </Body>
Second, insert the node
In the process of creating a node, we have actually demonstrated how to insert a node by using the. Append () method. But apart from this method, JQuery provides several other ways to insert nodes.
<Scripttype= "Text/javascript"src= "Jquery-1.12.3.min.js"></Script><Script>$(function(){ varBox= $('<div id= "box" > Add node </div>'); //Create a node $('Div'). append (box); //Insert a node behind a div inside a <body> element});</Script></Head><Body> <Div>Node</Div> <Div>Node</Div></Body>
<Scripttype= "Text/javascript"src= "Jquery-1.12.3.min.js"></Script><Script>$(function(){ $('Div'). Append (function(index, HTML) {//inserting nodes using anonymous functions, HTML is the original node return '<div> Nodes </div>'; });});</Script></Head><Body> <Div>Node</Div> <Div>Node</Div></Body>
Create node, insert node for jquery_dom node operation