Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    var BoxCollection = Array.from(document.getElementsByClassName("Box")); should do what you want Commented Jul 8, 2021 at 15:24
  • This is my code rn: ``` function BoxAppearence() { var Box = Array.from(document.getElementsByClassName("Box")); console.log(Box); console.log(Box[12]); } BoxAppearence(); ``` But in console it's shows: [] and undefined Commented Jul 8, 2021 at 17:03
  • As you can see in this JSFiddle snippet, it works; are you sure you provided the correct class name (remember JavaScript is case-sensitive and "Box" is not the same as "box")? Are you sure your page contains elements with the "Box" class? Are you sure you are executing the function after the DOM has completely loaded? Commented Jul 9, 2021 at 7:15
  • Does this answer your question? Most efficient way to convert an HTMLCollection to an Array Commented Jul 9, 2021 at 7:57