javascript - 删除 :active pseudo-class from an element

标签 javascript pseudo-class

我希望能够告诉一个元素它不再是 :active 以便 CSS 规则不再适用。有没有办法在 JavaScript 中做到这一点?

最佳答案

可能的解决方案:

1) 使用类:

JS:

document.getElementById("element").classList.remove("hasactive");

CSS:

#element.hasactive:active {
    background:blue;
}

2) 阻止默认的 mousedown 功能(事件状态):

编辑:显然,这只适用于 Firefox。

JS:

document.getElementById("element").onmousedown = function(event) {
    event.preventDefault();
}

3) 删除带有 css 规则的样式元素

HTML:

<style id="activestyle">
#element:active {
/*Your code here*/
}
</style>

JS:

document.getElementById("activestyle").remove();

关于javascript - 删除 :active pseudo-class from an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22016522/

相关文章:

css - 两个元素中的第一个是否有伪类选择器?

css - 结构伪类和属性选择器不能一起工作

javascript - jQuery 多次延迟解析

javascript - react : Insert One Component After Another

javascript - D3 区分具有拖动行为的元素的单击和拖动

html - 在 React 中设置 CSS 伪类的样式

html - 为什么第 nth-of-type/nth-child 不适用于嵌套元素?

css - 具有相同伪类的多个选择器

javascript - Google map v3 在 jQuery mobile 和 PhoneGap 上具有自动完成功能

javascript - 通过sequelizejs从mysql数据库将数据加载到图表中