+ 7
Is it possible to set styles to pseudo elements in Javascript?
Kindly show your workaround code 😉
10 odpowiedzi
+ 6
I doesn't seen 'in javascript' when I previously read your question ^^
You cannot set pseudo-style element by classical way of using 'style' attribute of html element, but you can:
- set a classname to this element, with style definition for the targeted pseudo-element ( easiest )
- set dynamically style sheet rules ( hardiest - require browsers specificities: not handle by same way in ie, firefox, chrome... )
+ 5
@visph. I need to check how to set style to pseudo elements in JAVASCRIPT.
+ 5
@Very Hard:
What a great sharing stuff ^^ : you post in comment instead answer here, and delete it quickly :P
Anyway... I'm probably wrong, but using querySelector() method with pseudo-element selector seems not to work :( ( but I have no more time now to continue testing, and I cannot look again at your deleted comment )
+ 4
Yes; to be sure we are sharing the same definition of "pseudo element" ;P
... and first link provide styling example ( no need of workaround, as you can ^^ )
+ 4
document.querySelector('div::before') will return null with this in html:
<style>div::before { content:'before'; }</style>
<div>test</div>
+ 3
Hi @visph. This is css reference.
+ 3
@Very hard 😕
+ 3
Thanks anyway @Very. I got it.
+ 3
@visph you're right. Js cannot set the style directly. I have the other method to workaround this now by remove and add class