0

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 = " ";
}
4

1 に答える 1

3

要素の配列ではなく、一致した要素のクラス名を修正する必要があるため:

var classMatches = document.querySelectorAll(".crux.attachFlash");
for (var i = 0; i < classMatches.length; i++) {
    classMatches[i].className = " ";
}

[i]インデックスを忘れたのでclassName、配列全体を設定しようとしていました(これは、あなたが見つけたように機能しません)。

于 2012-06-05T22:19:59.433 に答える