I am trying to better my Javascript knowledge and I am struggling. I have a list in HTML. I want the bullet points of each element to be a random hex color.
function generateColor() {
var hex = "";
var range = "abcdef0123456789";
for (var i = 0; i < 6; i++) {
hex += range.charAt(Math.floor(Math.random() * range.length));
}
$('li:before').css('color', '#' + hex);
}
$('li:before').on('keypress', function(event) {
if (event.keyCode == 32) {
generateColor();
}
});
generateColor();
ul {} li {
list-style: none;
}
li:before {
content: "■ ";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Dilemma: I don't think I can change the List-Style elements color period.
I found a way around this, by using the :before tag in my css for the "List Item"...
By doing that I am able to use any ASCII symbol as my list element.
I looked online for a few examples to change the Color: aspect of my li:before style. However, I don't think the function likes the :before part of my CSS.
I am stumped, Is what I want to do even possible?