In Javascript, I have a function that should find elements on a page that have a "connected" class, and when I click a button, the classes for these elements are cleared. I wrote this code:
var prev_connected = document.getElementsByClassName("connected"); if (prev_connected.length > 0) { for (var j = 0; j < prev_connected.length; j++) { prev_connected[j].removeAttribute("class"); } }
However, it only removes the class attribute of the first "connected" element on the page. When I have two βconnectedβ elements, I confirmed that the prev_connected array has 2 values, but for some reason the for loop never reaches the second. Is there something I'm doing wrong? Thanks.
source share