javascript - How to get pseudo element's computed value?
问题描述
I have a counter in a psuedo class in my CSS, something like this,
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
and I want the computed value of counter.
I have tried using
getComputedStyles(document.getElementById("1"), '::before')
but that returns Section " counter(section) ":
, whereas I am trying to get the actual value that it displays. which is Section 1:
This is the demo HTML snippet that I have been testing with,
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
<h2 id="1">HTML Tutorial</h2>
解决方案
不幸的是,使用当前的 CSS 规范是不可能的。在这个答案中查看为什么以及该怎么做
推荐阅读
- arrays - Ciki boyutlu dizi Malloc
- angular - 切换所选行中的图标
- javascript - 根据一个字段在数组中查找 Javascript 结构
- ruby-on-rails - RSpec capybara:涉及 Ajax 的测试单独通过但一起运行时失败
- python - 手动移动散点图数据
- google-cloud-platform - 无法为我在 GCP 中的帐号授予结算管理员角色
- c# - 根据某些字符或长度在 razor 中操作字符串
- java - 为什么gluon移动链接任务在ubuntu上失败?
- javascript - useReducer 没有使用 useEffect 更新状态
- python - 在python中制作使用绝对和相对目录路径的模块