I need to find a way to change CSS :hover properties using JavaScript.

For example, suppose I have this HTML code:

<table>
<tr>
<td>Hover 1</td>
<td>Hover 2</td>
</tr>
</table>

And the following CSS code:

table td:hover {
background:#ff0000;
}

I would like to use JavaScript to change the <td> hover properties to, say, background:#00ff00. know I could access the style background property using JavaScript as:

document.getElementsByTagName("td").style.background="#00ff00";

But I don't know of a JavaScript equivalent for :hover. How do I change these <td>'s :hover background using JavaScript?

Pseudo classes (like :hover) never refer to an element, but to any element that satisfies the conditions of the stylesheet rule. You need to edit the stylesheet ruleappend a new rule, or add a new stylesheet that includes the new :hover rule.

var css = 'table td:hover{  padding: 0px; border: 0px; color: rgb(48, 51, 54);">;
style = document.createElement('style'); if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
} document.getElementsByTagName('head')[0].appendChild(style);

Change :hover CSS properties with JavaScript的更多相关文章

  1. 梅须逊雪三分白,雪却输梅一段香——CSS动画与JavaScript动画

    CSS动画并不是绝对比JavaScript动画性能更优越,开源动画库Velocity.js等就展现了强劲的性能. 一.两者的主要区别 先开门见山的说说两者之间的区别. 1)CSS动画: 基于CSS的动 ...

  2. Hover.css:一组超实用的 CSS3 悬停效果和动画

    Hover.css 是一套基于 CSS3 的鼠标悬停效果和动画,这些可以非常轻松的被应用到按钮.LOGO 以及图片等元素.所有这些效果都是只需要单一的标签,必要的时候使用 before 和 after ...

  3. 谷歌浏览器 查看源码里的a:hover CSS样式 还有火狐的查看方式

    谷歌浏览器查看hover css样式 直接实例: 选中a标签 然后右侧面板 出现 箭头 点击 出现Toggle Element state提示 下面再hover前打勾 直接就可以显示效果了 浏览器查看 ...

  4. Webkit CSS properties

    Webkit CSS properties -webkit-animation -webkit-animation-delay -webkit-animation-direction -webkit- ...

  5. 让IE6支持position:fixed的方法,CSS expression与JavaScript eval讲解

    做吸顶效果或是固定效果时,使用position:fixed无非是最方便的,可是万恶的IE6是没有fixed这个属性值的,而我们要使IE6能够像fixed一样固定在浏览器中的某个位置,使用onscrol ...

  6. CSS3悬停特效合集Hover.css

    CSS3悬停特效合集Hover.css是一款特效丰富,支持2D变化特效.边框特效.阴影特效等: 使用简单,可直接复制相关特效代码,快速应用到元素上. 源码地址:http://www.huiyi8.co ...

  7. CSS skills: 2) change hover dynamically by js

    //命名空间 var base = {}; //class base.gClass={}; //鼠标hover交互方法: 注册对象的hover的class特性以及mouseMoveIn,mouseMo ...

  8. CSS补充与JavaScript基础

    一.CSS补充 position 1.fiexd 固定在页面的某个位置; 示例将顶部菜单始终固定在页面顶部 position: fixed; 将标签固定在某个位置 right: 0; 距离右边0像素 ...

  9. Python之路-python(css布局、JavaScript)

    CSS布局 JavaScript css布局: 后台管理界面一:(左右标签都有下来菜单) 利用position: absolute;让某个标签固定在具体位置,然后使用overflow: auto;属性 ...

随机推荐

  1. CodeForces 1251B --- Binary Palindromes

    [CodeForces 1251B --- Binary Palindromes] Description A palindrome is a string t which reads the sam ...

  2. 【VS开发】VSTO 学习笔记(十)Office 2010 Ribbon开发

    微软的Office系列办公套件从Office 2007开始首次引入了Ribbon导航菜单模式,其将一系列相关的功能集成在一个个Ribbon中,便于集中管理.操作.这种Ribbon是高度可定制的,用户可 ...

  3. 2019牛客暑期多校训练营(第七场)-E Find the median (线段树+离散化 区间为点)

    题目链接:https://ac.nowcoder.com/acm/contest/887/E 题意:给出L[i],R[i],每次添加L[i]...R[i],求出此时的中位数. 思路:因为添加的数范围为 ...

  4. scrapy生成json中文为ASCII码解决

    修改pipelines.py 即可 修改内容如下: import json import codecs import os class BaiduNewsPipeline(object): #增加的 ...

  5. quartus ii 粗略使用教程

    重复刚刚做过的下载程序,不选sof文件,选择jic文件 选择program config然后点击start,观察开发板,断电在开启后仍然有效果,想要擦除开发板flash文件,可以点击取消program ...

  6. 小记--------spark的宽依赖与窄依赖分析

    窄依赖: Narrow Dependency : 一个RDD对它的父RDD,只有简单的一对一的依赖关系.RDD的每个partition仅仅依赖于父RDD中的一个partition,父RDD和子RDD的 ...

  7. SQLite基础-6.运算符

    目录 SQLite 运算符 1. 运算符 2. 算数运算符 3. 比较运算符 4. 逻辑运算符 SQLite 运算符 1. 运算符 首先,问大家运算符是什么?运算符在很多领域均用使用.它也分很多中,常 ...

  8. 15-Perl 格式化输出

    1.Perl 格式化输出Perl 是一个非常强大的文本数据处理语言.Perl 中可以使用 format 来定义一个模板,然后使用 write 按指定模板输出数据.Perl 格式化定义语法格式如下:fo ...

  9. 你真的知道em和rem的区别吗?

    前言 em 和 rem 都是相对单位,在使用时由浏览器转换为像素值,具体取决于您的设计中的字体大小设置. 如果你使用值 1em 或 1rem,它可以被浏览器解析成 从16px 到 160px 或其他任 ...

  10. O045、理解 Cinder 架构

    参考https://www.cnblogs.com/CloudMan6/p/5573159.html   从本节开始我们学习OpenStack 的 Block Storage Service ,Cin ...