當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
JS小技巧
JS操作偽元素
CSS代碼:
#myId:before {content: "hello world!";display: block;width: 100px;height: 100px;background: red; }JS 代碼:
var myIdElement = document.getElementById("myId"); var beforeStyle = window.getComputedStyle(myIdElement, ":before"); console.log(beforeStyle); // [CSSStyleDeclaration Object] console.log(beforeStyle.width); // 100px console.log(beforeStyle.getPropertyValue("width")); // 100px console.log(beforeStyle.content); // "hello world!"這樣就獲取到為元素的樣式了,那么改如何操作呢?
轉(zhuǎn)載于:https://www.cnblogs.com/guolaomao/p/6598219.html
總結(jié)
- 上一篇: 平安银行循环信用是什么?循环信用额度多少
- 下一篇: gradle idea java ssm