::before
CSS3で設定されたDOM要素のコンテンツを取得できるかどうか知りたい。
私はいくつかの方法を試しましたが、それでもそれを行うことができないので、それは私にとって非常に混乱しています!
// https://rollbar.com/docs/
const links = document.querySelectorAll(`ul.image-list a`);
links[0];
// <a href="/docs/notifier/rollbar-gem/" class="ruby">::before Ruby</a>
links[0];
//
links[0].textContent;
//"Ruby"
links[0].innerText;
// "Ruby"
links[0].innerHTML;
// "Ruby"
// ??? links[0]::before;
これが当てはまります:
推奨される回答1
":before"
2番目のパラメータとしてwindow.getComputedStyle()
:に渡します。
console.log(getComputedStyle(document.querySelector('p'), ':before').getPropertyValue('content'));
p::before,
p::after {
content: ' Test ';
}
<p>Lorem Ipsum</p>
推奨される回答2
getComputedStyle()&getPropertyValue()
getComputedStyle(document.querySelector('span.search-box'), '::after').getPropertyValue('content');