February 2018
Intermediate to advanced
298 pages
8h 22m
English
Similar to the ID method, getElementsByTagName(<Name Of Tag>) gets us elements with a couple of differences:
Here's an example:
<div>My Content Here</div><script>const div = document.getElementsByTagName('div')[0];div.innerHTML = "Cool"; // above div's text is replaced with "Cool"</script>
Notice the word getElements. It returns us a bunch of elements. Therefore, we pick up the first element from the NodeList and set its contents to Cool.
innerHTML is used to change the HTML content inside the element you're working on.
Read now
Unlock full access