+ 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 Antworten
+ 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😅🙏