Home >Web Front-end >JS Tutorial >How to create element nodes in jquery
Jquery method of creating element nodes: first create a p tag, add an id attribute to the p tag; then obtain the p element object through the id, and use the [append()] method to add nodes to the p tag.
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.
How to create element nodes with jquery:
1. Create a new html file, named test.html, to explain how jquery creates element nodes.
2. In the test.html file, create a p tag, and then add an img node within the p tag.
3. In the test.html file, add an id attribute to the p tag, which will be used to obtain the p tag object below.
4. In the test.html file, use the button tag to create a button, bind the onclick click event to the button, and when the button is clicked, execute createle ()
function.
5. In the js tag, create the createle() function. Within the function, obtain the p element object through the id and use the append()
method. Add img node to p tag.
#6. Open the test.html file in the browser and click the button to view the results.
Related free learning recommendations: javascript (video)
The above is the detailed content of How to create element nodes in jquery. For more information, please follow other related articles on the PHP Chinese website!