WebMasterCampus
WEB DEVELOPER Resources

Javascript InnerHTML Is Not a Function It Is a Property

Learn Javascript InnerHTML Is Not a Function It Is a Property


Javascript InnerHTML

The innerHTML property gets or sets the HTML or XML markup contained within the element.

.innerHTML Common Mistake

- document.getElementById("message").innerHTML ( " Updated Content" );  //error it's not a function, it's a property

First, please understand that .innerHTML is not a function, It is a property. We assign values to property using equals sign “=”.

.innerHTML Syntax

element.innerHTML = "Assign htmlString";

Example

    // add div tag with id message like <div id='message'></div> in html

    <div id='message'></div>
    
    <script>
        var msg = " Updated Content";
        document.getElementById('message').innerHTML = msg;
    <script>

mozilla developer innerHTML

Created with love and passion.