I\'m trying to get each letter in a div element to change to a random colour from an array of colours. Then reset when the mouse moves off the div.
Here\'s what I\'v
You can only add styles to elements, wrap each character in a and style the span.
#header {color: #ffffd}
Some text here
$(document).ready(function() {
// COLOURS ARRAY
var colours = Array("#ffffd", "#333", "#999", "#bbb"), idx;
$("#header").hover(function(){
var header = $(this);
var characters = header.text().split('');
header.empty();
var content = '';
for(var i = 0; i < characters.length; i++) {
idx = Math.floor(Math.random() * colours.length);
content += '' + characters[i] + '';
}
header.append(content);
}, function() {
$(this).find('span').contents().unwrap();
});
});
http://jsfiddle.net/vVNRF/