javascript - 是否可以仅使用 JS 选择 CSS psuedo::after 内容的内容?
问题描述
我找到了引用 JQuery 的帖子,但我想知道是否可以在元素上获取 psuedo::after 元素的文本内容字符串。
如果我选择了有问题的元素,例如document.querySelectorAll('.checkout-form-error')[0];
如何选择文本字符串“需要邮政编码字段”。使用 JS?
解决方案
这可以通过window.getComputedStyle助手来完成。
var str = window.getComputedStyle(document.querySelector('.mock'), ':after').getPropertyValue('content');
console.log(str)
.mock::after{
content: "we need to get this text ye?"
}
<div class="mock">
</div>
推荐阅读
- python - Python inheritance causes illegal attribute error
- vue.js - 在 Vue 中将对象属性与子组件同步
- python - How to make a new df from random subset of rows from another df without duplicates?
- bootstrap-4 - bootstrap-validate for select inputs for bootstrap 4
- html - How to make slow animation of a div from right to left on click a button in angular 7
- javascript - How can I move pieces / images from a checkerboard on Canvas using JavaScript?
- c# - C# CngKey ECDelfieHellmanP521
- python - How to optimize the process of building two graphs in real time based on Pandas DataFrame
- c# - asp.net 母版页 css 不适用于 asp 表单页面
- jquery - CSS3 过渡和变换元素和代码检查异常的问题