私はクラスhardware
を持っています。これをクリックすると、run
の機能に当たって背景色を変更したいと思います。しかし、私のクリックはそれらを一度に同じ色に設定します。各クラスアイテムのクリック機能
hardware
とそれぞれのクリックイベントを区別するにはどうすればよいですか?
function run(){
var selector = document.getElementsByClassName('hardware');
for (var i = 0; i < selector.length; i++){
var index = selector[i];
selector[i].style.backgroundColor = "hotpink";
}
}
<section onclick="run()" class="hardware">some text, nth-child is one</section>
<section onclick="run()" class="hardware">some text, nth-child is two</section>
<section onclick="run()" class="hardware">some text, nth-child is three</section>
<section onclick="run()" class="hardware">some text, nth-child is four</section>
<section onclick="run()" class="hardware">some text, nth-child is five</section>