Using Javascript, I would like change the background color of the numbers in an ordered HTML list. The background color of the list content should not change.
How can I achieve this ?
Using Javascript, I would like change the background color of the numbers in an
Share
Based on the following article : Style Ordered List with CSS, if you have some HTML code like this :
Then, using a CSS that looks like this :
Might get you something like what you’re asking for : here’s the result I get (only tested with Firefox) :
(source: pascal-martin.fr)
(There are more explanations on the article I linked to at the beginning of my answer)
EDIT after the comment : ooops, didn’t see that part ; sorry 🙁
Now that you have an ordered list, with a specific color as background for the numbers, you can plug-in some Javascript code, to change that color.
Considering that the
<ol>tag I used here asid="list", you can change its background-color with the following portion of JS code :After this is executed, you’ll get something that looks like the following :
(source: pascal-martin.fr)