+ 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 Answers
+ 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š
š