如何获得伪元素的信息
JS无法直接获取元素的:after伪元素节点,因为它不是DOM节点。但是可以使用getComputedStyle方法获取元素的样式,进而获取:after伪元素的内容。
示例代码:
// 获取元素
const element = document.querySelector('.my-element');
// 获取元素的样式
const styles = window.getComputedStyle(element, '::after');
// 获取伪元素的内容
const content = styles.content;
console.log(content);