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>
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
Save the html code and open it with a browser. You can see that the page displays the text content in the div tag.
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";
Save the html code, and then open it with a browser to see that the browser page displays text modified using 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!