Home >Web Front-end >JS Tutorial >How to modify div content with javascript
How to modify the content of a div using JavaScript: First add the id and text content to the tag and create a [<script>]; then use the innerHTML attribute to modify the text content inside the div; finally open it with a browser . </script>
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
How to modify div content using JavaScript:
1. Open the HTML development tool, create a new HTML page, then create a
#2. Save the html code and open it with a browser. You can see that the page displays the text content in the div tag.
3. Return 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";
4. Save the html code, and then open it with a browser to see that the browser page is modified using JavaScript text.
Related free learning recommendations: javascript learning 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!