Sunday, 30 September 2018

JavaScript: innerHTML: Set (or) get HTML data

By using Element.innerHTML property, you can set (or) get the HTML syntax describing the element's descendants.

process.js
function processData(){
         var content = document.getElementById("data1").innerHTML;
         alert("Inner HTML is : " + content);
         alert("Adding new content to second div section");
         document.getElementById("data2").innerHTML = content;
}

window.onload = processData;

innerHtml.html
<!DOCTYPE html>

<html>

<head>
    <title>innerHTML Example</title>
    <script src="process.js"></script>
</head>

<body>

    <div id="data1">
        <p>
            <h1>Very Good Morning Hari</h1>
        </p>
    </div>

    <div id="data2">

    </div>
</body>

</html>




Previous                                                 Next                                                 Home

No comments:

Post a Comment