Im really having a great bad time when using JS Selectors! Before anything else, Heres my Code!
<body>
<div class="container">
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
</div>
</body>
var colors = [
"rgb(255 , 0 , 0)",
"rgb(255 , 255 , 0)",
"rgb(0 , 255 , 0)",
"rgb(0 , 255 , 255)",
"rgb(0 , 0 , 255)",
"rgb(255 , 0 , 255)",
];
var squares = document.getElementsByClassName("square");
alert(squares.length)
That is my code in my scripts.js! so when i try to open the webpage, it alerts 0, yeah 0 instead of the real length of the Divs which is 6, but when i play with the console typing this:
squares.length;
It returns 6, which is cool! Whats wrong!?