I'm trying to use jquery to make a css selector randomize one of its values on an html element. I've gotten as far as randomizing the selector for all of the elements (cycling through colors on a list border-left), however I want to randomize each individual list element at the same time.
Apologies if that's confusing (I'm confused by it myself), but you'll understand if you run the below code a few times and watch the border color change. Ideally, those border colors would all be different.
Thanks very much for any help.
<html>
<head>
<title>Title</title>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<style>
.bars{
border-left-style: solid;
border-left-width: 4px;
padding-left: 10px;
}
ul{
list-style-type: none;
}
</style>
</head>
<body>
<ul>
<li class="bars">
<a>Marathon Men and Women</a>
</li>
<li class="bars">
<a>Marathon Men and Women</a>
</li>
<li class="bars">
<a>Marathon Men and Women</a>
</li>
<li class="bars">
<a>Marathon Men and Women</a>
</li>
<li class="bars">
<a>Marathon Men and Women</a>
</li>
</ul>
</body>
<script>
$(document).ready(function(){
var colors = ["#CCCCCC","#333333","#990099"];
var rand = Math.floor(Math.random()*colors.length);
$('.bars').css("border-left-color", colors[rand]);
});
</script>