使用JavaScript获取CSS伪元素属性

 我们可以通过DOM元素的 style 属性获取基本的CSS样式值, 但怎么获取CSS伪元素属性呢? 如下

// 获取 .element:before 的 color 值
var color = window.getComputedStyle(
    document.querySelector('.element'), ':before'
).getPropertyValue('color');
 
 
// 获取 .element:before 的 content 值
var content = window.getComputedStyle(
    document.querySelector('.element'), ':before'
).getPropertyValue('content');

 

posted on 2014-01-24 11:45  dubaokun  阅读(1736)  评论(0编辑  收藏  举报

导航

新浪微博 新博客 Github