my CSS pseudo-code is not recognised by jQuery: here's my code
css:
h1 {
background: red;
width: 100px;
display: inline-block;
}
h1:after {
content:" | ";
background:blue;
display: inline-block;
}
then in jQuery i do:
console.log($('h1').css('backgroundColor'));
is shows:
rgb(255, 0, 0)
but when i do:
console.log($('h1:after').css('backgroundColor'));
is shows:
undefined
The after() is an inbuilt function in jQuery which is used to insert content, specified by the parameter for the each selected element in the set of matched element. Syntax: $(selector). after(A);
You can't. A pseudo element is not in the DOM so can't be selected by JS.
Since they're not part of the DOM, CSS pseudo-elements can't be selected and edited with JavaScript the same way as traditional elements on a page.
jQuery insertAfter() Method The insertAfter() method inserts HTML elements after the selected elements. Tip: To insert HTML elements before the selected elements, use the insertBefore() method.
You cannot select css pseudo-elements because they don't actually exist in the DOM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With