Home>Article>Web Front-end> How to create element nodes in jquery

How to create element nodes in jquery

coldplay.xixi
coldplay.xixi Original
2021-03-01 17:44:20 3247browse

Jquery method of creating element nodes: first add an img node in the p tag and add an id attribute; then bind the onclick click event to the button; finally use the [append()] method to add to the p tag img node.

How to create element nodes in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, DELL G3 computer. This method is suitable for all brands of computers.

How to create element nodes with jquery:

1. Create a new html file, named test.html, to explain how jquery creates element nodes.

How to create element nodes in jquery

2. In the test.html file, create a p tag, and then add an img node within the p tag.

How to create element nodes in jquery

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.

How to create element nodes in jquery

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, executecreatele ()function.

How to create element nodes in jquery

5. In the js tag, create thecreatele()function. Within the function, obtain the p element object through the id and useappend ()Method adds img node to p tag.

How to create element nodes in jquery

#6. Open the test.html file in the browser and click the button to view the results.

How to create element nodes in jquery

Recommended:jquery video tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn