Friday, 8 December 2017

JavaScript | innerHTML Property in JavaScript

innerHTML property can be used to modify an HTML document. innerHTML property exists in all the types of the major Browsers. 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.

Syntax
The syntax for using innerHTML looks like this:
document.getElementById('ID of element').innerHTML = new HTML content;

getElementById: getElementById refers to the HTML element using its ID.
new HTML content: Data is the new content to go into the element.

<!DOCTYPE html>
<html>
<body>
    <p id="demo" onclick="changeInnerHTML()">Click me to change my HTML content (innerHTML).</p>

    <script>
        function changeInnerHTML() {
            document.getElementById("demo").innerHTML = "Paragraph changed!";
        }
    </script>
</body>
</html>


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...