I need help finding an element with a specific class name and then replace it with a new class name. Here is the code I came up with. I get no results. The class name does not change, and there are no errors in the console.
Updated Code:
var classMatches = document.querySelectorAll(".crux.attachFlash");
for (var i = 0; i < classMatches.length; i++) {
classMatches[i].className = " ";
}
Because you need to amend the class-name of the matched element, not the array of elements:
You forgot the
[i]index, so you were trying to set theclassNamefor whole array (Which, as you’ve found, does not work).