+ 24
[Solved] Can we also select after and before pesudo of an element by JavaScript ?
I have a question how can we select element::after and element::before pesudo by a JavaScript! HTML: <div class="element"></div> CSS : .element{ //your code} .element::after{ //your code} .element::before{ //your code} JS: //How can I select the pseudo element and give style to them ? //Also I know about jQuery it can select easily , but I want to know this in JavaScript!
7 RĂ©ponses
+ 10
So easy bro
There is the one way
Use getComputedStyle() function bro
https://code.sololearn.com/WdXBa21hv548/?ref=app
Second thing you can use CSS variable and then change their values with javascript
DIVYANSHU KR đș hope this help you bro đ
+ 7
I think there is no way to do that with JS..đ€·ââïž
+ 7
DIVYANSHU KR đș Yeah, if it happens, it will be very intetesting to learn!! So, thank you for posting this questionđđđ
+ 5
Coder i understand now how we can read the value of any property of pseudo-element using getComputedStyle()đthank you!! But how can we manipulate these propertiesâ values? For example, i want to change pseudo-elementâs value âredâ of property âcolorâ for âgreenâ, what should i do?đ€·ââïž
+ 5
Mikhail you can set the property of Pseudo element by JavaScript becoz they not in DOM elements the best way to do it is to use CSS variable
Use CSS varible then change it through JavaScript
Hope this help you bro đ
I tried to change it bro I got no modification error
+ 5
Coder i need to learn css variables for this as wellđ i donât know them yetđ€·ââïž ok thank you!
P.s. if i donât understand it, iâll ask again for your helpđ
đ