manipulate html elements using javascript

manipulate html elements using javascript

manipulate html elements using javascript

To access an HTML element from JavaScript, you can use the document.getElementById(id) method.
Use the "id" attribute to identify the HTML element, and innerHTML to refer to the element content:

<html>
<head>
<script>
function getValue()
  {
  var x=document.getElementById("myHeader");
  alert(x.innerHTML);
  }
</script>
</head>
<body>

<h1 id="myHeader" onclick="getValue()">Click me!</h1>

</body>
</html>

the above is JavaScript code for finding an HTML element using the id attribute.
innerHTML = "Paragraph changed." is JavaScript code for changing an element's HTML content (innerHTML).

 

Article by Morning Train Technologies

Marius Vaduva