使用JavaScript更改CSS偽元素


Posted by hoyi-23 on 2021-06-17

這裡提供一個很簡單的作法:

HTML

<div class="box" some-attribute-name=""></div>

CSS

.box::before{
    content= attr(some-attribute-name);
}

JavaScript

var box = document.querySelector('.box');
box.setAttribute('some-attribute','要新增的屬性值');

#偽元素 #javascript







Related Posts

[FE301] React 基礎(Class component 版):React 環境建置

[FE301] React 基礎(Class component 版):React 環境建置

[SQL] Want to declare a string array variable? Declare a table variable instead.

[SQL] Want to declare a string array variable? Declare a table variable instead.

[演講筆記] 突破學習困境與職涯瓶頸的行動指南 - 學習長阿康 : 我的人生策略與學習方法論

[演講筆記] 突破學習困境與職涯瓶頸的行動指南 - 學習長阿康 : 我的人生策略與學習方法論


Comments