Home >Web Front-end >JS Tutorial >jQuery study notes: Creating DOM elements_jquery

jQuery study notes: Creating DOM elements_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:19:221048browse

Using DOM methods to create element nodes usually requires the use of document.createElement(), document.createTextNode(), and appendChild(), which is very troublesome.

And jQuery can directly create DOM elements using $

Copy code The code is as follows:

var oNewP = $("

Content created with jQuery

");

The above code is equivalent to javascript

Copy code The code is as follows:

            var oNewP2 = document.createElement("p");
                var oText = document.createTextNode("This is content created using the javascript method");
              oNewP2.appendChild(oText);

Example: Using jQuery to create DOM

Copy code The code is as follows: