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

How to modify div content with javascript

青灯夜游
青灯夜游Original
2021-04-19 17:31:108230browse

Javascript method to modify div content: First use the "document.getElementById('id value')" statement to obtain the div object according to the id value; then use the innerHTML attribute to modify the div content, the syntax "div object.innerHTML=' value'".

How to modify div content with javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Javascript method to modify div content:

html code:

<div id="updateId">将要被修改的div</div>

js code:

<script type="text/javascript">
function changeText(){
document.getElementById(&#39;updateId&#39;).innerHTML = &#39;hello world!&#39;;
}
</script>

How to modify div content with javascript

Description:

The getElementById() method returns a reference to the first object with the specified ID.

The innerHTML property sets or returns the HTML between the opening and closing tags of a table row.

[Recommended learning: javascript advanced 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!

Statement:
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