How to get a DOM element's ::before content with JavaScript?

后端 未结 2 852
旧时难觅i
旧时难觅i 2021-02-04 03:12

I want to know whether it is possible to get a DOM element\'s ::before content, which was set by CSS3.

I have tried some ways, but I still can\'t make it, s

2条回答
  •  一个人的身影
    2021-02-04 03:59

    Pass ":before" as the second parameter to window.getComputedStyle():

    console.log(getComputedStyle(document.querySelector('p'), ':before').getPropertyValue('content'));
    p::before,
    p::after {
      content: ' Test ';
    }

    Lorem Ipsum

提交回复
热议问题