How to change in html data using JavaScript?

0 votes
29 views
Ravi Vishwakarma asked 8 days ago in Web Application by Ravi Vishwakarma

How to change in html data using JavaScript? using innerHTML .

1 Answer

0 votes
Ethan Karla answered 5 days ago by Ethan Karla
We are use the innerHTML property for changing the inner data of html page.
Syntax
document.JavaScript-Selector.innerHTML = new-data;
Eaxmple
<!DOCTYPE html>

<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>Inner HTML</title>
    <style>
    </style>
</head>
<body>
    <span>Some Data : </span>
    <input type='text' id='txt' placeholder='some data please' />
    <button onclick='changeData()' >Change Data</button>
    <p id='fill'></p>
    <script>
        function changeData() {
            var data = document.getElementById('txt').value;
            document.getElementById('fill').innerHTML += data;
        }
    </script>
</body>
</html>