The content this article brings to you is about the method (code) of creating elements in JavaScript. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Dynamically create element one document.write()
For example, output a li tag to the page
Copy after login
It will be inserted into the body tag, but this method is rarely used, because it will affect the layout of the page and even wash away the original content of the page, thus only displaying the output content
2. Dynamically create element 2, innerHTML
, and a p tag will be inserted into the div tag, and "This is a tag" will be output on the page. This method is used when there are many tags to be added. .
3. Dynamically create element three document.createElement()
A li tag will be created under the div tag. When a dynamically created tag is required This method is used rarely
This article has ended here. For more exciting content, you can pay attention to the JavaScript Tutorial Video column on the PHP Chinese website. !
The above is the detailed content of JavaScript method to create elements (code). For more information, please follow other related articles on the PHP Chinese website!