test.html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script> var eles = document.getElementsByClassName('review'); console.log(eles); console.log(eles.length); console.log(eles[0]); </script> </head> <body> <div class="review"></div> <div class="review"></div> <div class="review"></div> <div class="review"></div> <div class="review"></div> </body>
I checked that eles represents an HTMLCollenction.
It says that HTMLCollection also exposes its members directly as properties by name and index.
So, I tried to debug console.log (eles.length) and console.log (eles [0]). But, unfortunately, the console shows 0 and undefined. (Using Google Chrome Tool Developer)
How can I access eles results? I want to change the style and add an attribute to the tags received by ClassName. In addition, I can only use natural Javascript.
source share