Home > Web Front-end > JS Tutorial > How to write html code in js

How to write html code in js

藏色散人
Release: 2023-01-06 11:15:18
Original
11768 people have browsed it

How to write html code in js: first use the div tag to create an area, add an id attribute to the div tag; then save a piece of html code in the html variable in js; finally use the innerHTML attribute, Simply write the html code dynamically into the div tag.

How to write html code in js

The operating environment of this article: Windows 7 system, javascript version 1.8.5, DELL G3 computer

Create a new html file, named test.html, Used to explain how to dynamically write html code using js.

How to write html code in js

In the test.html file, use the div tag to create an area for dynamically outputting the html code within the div.

How to write html code in js

In the test.html file, add an id attribute to the div tag, which is used to obtain the div object below.

How to write html code in js

In the js tag, save a piece of html code in the html variable.

How to write html code in js

In the js tag, obtain the div object through the id, and use the innerHTML attribute to dynamically write the html code into the div tag.

How to write html code in js

Open the test.html file in the browser to check the effect.

How to write html code in js

Recommended: "javascript advanced tutorial"

The above is the detailed content of How to write html code in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template