Using the DOM method to create an element node, it is often troublesome to use document.createelement (), document.createTextNode (), AppendChild () in conjunction.
And jquery uses $ to create DOM elements directly
Copy Code code as follows:
var ONEWP = $ ("<p> content created with jquery </p>");
The above code is equivalent to JavaScript
Copy Code code as follows:
var oNewP2 = document.createelement ("P");
var otext = document.createTextNode ("This is the content created using the JavaScript method");
Onewp2.appendchild (Otext);
Example: Using jquery to create Dom
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
var ONEWP = $ ("<p> content created with jquery </p>");
Onewp.insertafter ("#display"); InsertAfter method
})
</script>
<div id= "Display" ></div>
Using jquery greatly shortens the length of your code. Save time for writing. I hope this article can give small friends some tips, have questions please give me a message.