- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › pesudo element change property values
hi guys.
is impossible to change a property value in style.css by search and replace.
for ex . I want to change width of a psudo element dynamicly.
span:after{
content:"";
top:0;
left:0;
position: absolute;
background-color:red;
height:20px;
width:0;
}
and this is the best practice.or website maybe slow.
thanks.
Pseudo-elements can’t be selected by JS as the aren’t in the DOM.
Frankly, I’m not entirely sure what it is you are trying to do but changing the CSS stylesheet would require a regex parse I think.
These things are usually handled by changing classes and affecting the pseudo-elements that way.
Pseudos can be selected with JS (which I didn’t realise until shortly) but are only readable. Changing their properties isn’t possible. What you would be looking for is this:
https://developer.mozilla.org/en-US/docs/Web/API/CSSRule
Like Paulie mentioned, the script will need to use a regex and go through the entire stylesheet to find a match. Both the external accessing of the file and especially this search will certainly be a slow and “intensive” approach.
An example, I found it quite complicated: