Home > Web Front-end > JS Tutorial > How to modify div content with javascript

How to modify div content with javascript

coldplay.xixi
Release: 2023-01-05 16:13:17
Original
2022 people have browsed it

How to modify the content of a div using JavaScript: first create a tag and add content; then create a [<script>] tag and use the innerHTML attribute to modify the text content in the div; finally open it with a browser. </script>

How to modify div content with javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to modify div content using JavaScript:

Open the HTML development tool, create a new HTML page, then create a

tag and add id and text to the tag. content.

How to modify div content with javascript

Save the html code and open it with a browser. You can see that the page displays the text content in the div tag.

How to modify div content with javascript

Go back to the html code page, create a <script> on the html page, and then use the innerHTML attribute to modify the text content inside the div. </script>

JavaScript code:

document.getElementById("demo").innerHTML = "hello world";
Copy after login

How to modify div content with javascript

Save the html code, and then open it with a browser to see that the browser page displays text modified using JavaScript .

How to modify div content with javascript

Related free learning recommendations: javascript video tutorial

The above is the detailed content of How to modify div content with javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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