打开另一页后悬停样式

时间:2016-05-20 13:42:12

标签: mousehover

我有div的鼠标悬停样式,里面有一个href。 单击它时打开新的浏览器选项卡。当我回到原始页面时,悬停样式仍然存在,除非我将鼠标移到div之外。 我怎么解决这个问题?

谢谢

1 个答案:

答案 0 :(得分:0)

在所选元素上使用onclick事件

您使用document.getElementById选择div,然后在其上放置onclick事件并删除attribute,在这种情况下hover class



   var box = document.getElementById('hover');

   
   box.onclick = function(){
     box.removeAttribute("class")
    }

.test:hover {
  border:1px solid red;
}

<div id='hover' class="test"> 
   <a href="google.com" target="_blank">blah</a> 
   </div>
&#13;
&#13;
&#13;

相关问题