Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  90] [ 2]  / answers: 1 / hits: 15922  / 10 Years ago, wed, march 26, 2014, 12:00:00

How to change the :before content of #abc style from javascript ?



<script>
document.getElementById('abc').style.content='-';
</script>

<style>
#abc:before{content:+;}
</style>

More From » css

 Answers
1

No, you cannot access :before or :after from javascript, because they are not a part of the DOM. However you can still achieve your goal by using CSS classes:



<script>
document.getElementById('abc').className = minus;
</script>

<style>
#abc:before {content: +;}
#abc.minus:before {content: -}
</style>


In fact this approach is more unobtrusive, because you don't mix representation with javascript. Tomorrow you might want to change text +/- to say nice background images, in this case you don't have to touch javascript code at all.


[#71776] Monday, March 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondorlandok

Total Points: 530
Total Questions: 110
Total Answers: 96

Location: Lebanon
Member since Wed, Dec 21, 2022
1 Year ago
raymondorlandok questions
;