DOCUMENTGETELEMENTBYID()INNERHTML JAVASCRIPT SET EXAMPLE
Views: 160
document.getElementById().innerHTML javascript - how to set, Example
document.getElementById("id").innerHTML is a document object method that acces/manipulate element with the specified id.
The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR.
Description
"id" is The id of the element you want to read/write
Browser Support
The getElementById() method is supported in all major browsers: Internet Explorer, Firefox, Opera, Google Chrome, Safari
Example:
We have a div and want to write the content using document.getElementById("id").innerHTML.
<div id="your_div">Initial content or no content</div>
<a onclick="inner('your_div')">Change (write the content of "your_div")</a>
<script>
function inner(a){
document.getElementById(a).innerHTML="NEW CONTENT WRITED WITH document.getElementById().innerHTML";
}
</script>
Demo:
Change (write the content of "your_div")
Initial content of "your_div" or no content
This method can be used on other event object like : onload, onkeypress, onmouseover etc.
document.getElementById("id").innerHTML can be used to write a xmlhttp.responsetext in this way document.getElementById(a).innerHTML=xmlhttp.responsetext; (without quotes because xmlhttp.responsetext is a defined variabile)
|
|