• 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!"

    这样就获取到为元素的样式了,那么改如何操作呢?

  • 相关阅读:
    暴躁游戏

    时间记录表格
    好好生活
    JAVA环境的配置
    Java简介
    markdown学习

    Arduino
    Arduino
  • 原文地址:https://www.cnblogs.com/guolaomao/p/6598219.html
Copyright © 2020-2023  润新知