Javascript Inbuilt Methods: Part I

Please follow & like us :)

Here are the JS DOM inbuilt methods to get these HTML tags/elements:

  • document.getElementById(id)
  • document.getElementsByTagName(name)
  • document.getElementsByClassName(class)
  • document.querySelector(*)
  • document.querySelectorAll(*)

We can use these methods to update the HTML Dynamically.

Here are the examples:

1 document.getElementById(id)

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to change the text in this paragraph.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>