Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Adding A forEach Function To An HTMLCollection JavaScript

<script>
function add()
{ 
const ele = document.getElementsByClassName("myclass");
each= []['forEach'];
HTMLCollection.prototype.forEach = each;
ele.forEach(show);
	 }
function show(q)
	 {
		 console.log(q);
		
	 }
      </script>
  </head>
  <body>
<button id="btn" onclick="add()">Press </button>
<div class="myclass" id="a">aaaa</div>
<div class="q" id="b">bbbb</div> 
</body>
</html>
 
PREVIOUS NEXT
Tagged: #Adding #A #forEach #Function #To #An #HTMLCollection #JavaScript
ADD COMMENT
Topic
Name
8+5 =