This article mainly introduces jQuery's method for creating DOM elements. The example analyzes jQuery's skill of using $ to directly create DOM elements, which has some reference value, for more information about how to use jQuery to create DOM elements, see the following example. Share it with you for your reference. The specific analysis is as follows:
Using the DOM method to create element nodes usually requires the combination of document. createElement (), document. createTextNode (), and appendChild (), which is very troublesome.
JQuery uses $ to directly create DOM elements.
The code is as follows:
Var oNewP = $ ("
Content created using jQuery
");
The above code is equivalent to javascript
The code is as follows:
Var oNewP2 = document. createElement ("p ");
Var oText = document. createTextNode ("This is the content created using the javascript method ");
ONewP2.appendChild (oText );
Example: use jQuery to create a DOM
The code is as follows: