Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

javascript access collections of elements

<div class="wrapper">
  <p class="box">Food</p>		<!-- Index Position 0 -->
  <p class="box">Drink</p>		<!-- Index Position 1 -->
  <p class="box">Books</p>		<!-- Index Position 2 -->
  <p class="box">Whatever</p>	<!-- Index Position 3 -->
</div>

<script>
var myCollection = document.getElementsByClassName("box");
console.log(myCollection)
myCollection[0].innerHTML = "I can change everything!"
</script>
 
PREVIOUS NEXT
Tagged: #javascript #access #collections #elements
ADD COMMENT
Topic
Name
2+7 =