Excerpt |
---|
When |
...
you assign ID for HTML entity for <p> tag or <div> tag, we can dynamically update its content. You can find the object by getElementById(), and do the necessary actions into innerHTML. For instance, you can do it like document.getElementById( "element_id").innerHTML = "hello, world!"; |
Like I mentioned above, the The way of coding is super simple.
...
2) Put necessary action using getElementByIDgetElementById( entity_name ).innerHTML = blah blah...
...
Code Block | ||||
---|---|---|---|---|
| ||||
<html> <!-- Programmed by Chun Kang --> <head> <title>Inner HTML Test 1</title> </head> <script> function addContent(element_id, strContent) { document.getElementById( element_id).innerHTML += strContent; } function initContentclearContent(element_id) { document.getElementById( element_id).innerHTML =""; } </script> <body> <p id="test1">Initial content<br><content...</p> <input type=button onclick="javascript:addContent('test1','hello<br>Hello vinus<br>Venus!');" value="helloHello vinusVenus!"><br> <input type=button onclick="javascript:addContent('test1','hello<br>Hello robo<br>Robo!');" value="helloHello roboRobo!"><br> <input type=button onclick="javascript:initContentclearContent('test1');" value="initClear"><br> </body> </html> |