How to generate different background colors for list elements automatically?
Here is the static html
code what should be displayed with different background-color.
<ul>
<li>
<a href=#">I am the first element</a>
</li>
<li>
<a href=#">I am the 2nd element</a>
</li>
<li>
<a href=#">I am the 3rd element</a>
</li>
</ul>
No chance to add class
or style
manually, so I think using jQuery is the easiest solution. Here is my first try:
$(document).ready(function() {
$('.toc > ul > li').each(function(e){
var n = $(this).children().text().length*222222;
var h = n.toString(16).substr(0,6);
$(this).css({'background-color':'#'+h});
//$(this).append(h);
});
});
The result is a bit ugly, and there are similar colors what make this script unusable.
Any other idea to make beautiful automatically colorized lists?