0% found this document useful (0 votes)
51 views

Inner HTML

The innerHTML property allows JavaScript to dynamically modify HTML content without page refreshes. It is used with getElementById to select an element and change its contents. For example, innerHTML can update a <p> element's text when a user clicks a button, displaying different messages without reloading the page.

Uploaded by

Reynhel Mabunga
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Inner HTML

The innerHTML property allows JavaScript to dynamically modify HTML content without page refreshes. It is used with getElementById to select an element and change its contents. For example, innerHTML can update a <p> element's text when a user clicks a button, displaying different messages without reloading the page.

Uploaded by

Reynhel Mabunga
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

JAVASCRIPT

InnerHTML

InnerHTML
The innerHTML property can be used to modify your
document's HTML on the fly.

When you use innerHTML, you can change the page's content without refreshing the page. This can make your website feel quicker and more responsive to user input.
The

innerHTML property is used along with getElementById within your JavaScript


code to refer to an HTML element and change its contents.

InnerHTML Sample Syntax


document.getElementById('{ID of element}').innerHTML = '{content}';
In this syntax example, {ID of element} is the ID of an HTML element and {content} is the new content to go into the element.

InnerHTML Example
<script type="text/javascript"> function Msg1(){ document.getElementById('myText').innerHTML = 'Thanks!'; } function Msg2(){ document.getElementById('myText').innerHTML = 'Try message 1 again...'; } </script> <input type="button" onclick="Msg1()" value="Show Message 1" /> <input type="button" onclick="Msg2()" value="Show Message 2" /> <p id="myText"></p>

getElementById refers to the HTML element by using its ID

You might also like