How to change the html elements by JavaScript?

0 votes
27 views
Ravi Vishwakarma asked 13 days ago in Web Application by Ravi Vishwakarma

How to change the html elements by JavaScript?    

1 Answer

0 votes
Ethan Karla answered 10 days ago by Ethan Karla

in javascript has some methods to to change the internal data, style and attributes.

  1. element.innerHTML
  2. element.style.style-name
  3. element.setAttribute
  4. element.attribute
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
    <style>
        .page {
            background-color:green;
            }
    </style>
</head>
<body>
    <p id='p2'>Some data is available</p>
    <p id='p3'>Some data is available</p>
    <p id='p1'>Some data is available</p>
    <script>
        document.getElementById('p2').innerHTML += ' this is inner HTML';
        document.getElementById('p3').setAttribute('class', 'page');
        document.getElementById('p1').style.backgroundColor='red';
    </script>
</body>
</html>