如何在div儿童中定位

时间:2020-08-05 04:26:54

标签: javascript event-handling

我有多个div作为按钮,我使用循环和addEventListener来触发MouseOverMouseOut事件,但无法将div内的孩子作为目标,谢谢您的帮助

var btn = document.querySelectorAll('.c-btn');
var btnback = document.querySelectorAll('.btnback');

for (i = 0; i < btn.length; i++) {
  btn[i].addEventListener("mouseover", function(event){
    this.classList.add("rotatinEffect");
    btchild[i].style.backgroundColor = 'red'
  });

  btn[i].addEventListener("mouseout", function(){
    console.log('out')
    this.classList.remove("rotatinEffect");
    btchild[i].style.backgroundColor = 'blue'
  });
}

0 个答案:

没有答案
相关问题