I am trying to make every letter in a small line of text a different random color. I can only seem to make it do this when I use .hover, but I want it to do the action strai
var colours = ["#000000", "#FF0000", "#990066", "#FF9966", "#996666", "#00FF00", "#CC9933"],
idx;
$(function() {
var div = $('#arch');
var chars = div.text().split('');
div.html('');
for(var i=0; i' + chars[i] + '').css("color", colours[idx]);
div.append(span);
}
});
Works for me. jsFiddle
You have to make sure the DOM is loaded before doing any jQuery stuff on it.
http://learn.jquery.com/using-jquery-core/document-ready/