jquery - Randomly changing colors of specified elements within one div or post -
i have in mind design idea elements of post have same random color values.
example:
<post> <top border-top = random color> <h1 color = same random color> text body copy (not random color) <div background = same random color> more elements (not random color) <bottom border-bottom = same random color> <end post>
i have tried on own , got this, couldn't figure out how select multiple elements.
http://jsfiddle.net/r74j6/200/
function get_random_color() { var letters = '0123456789abcdef'.split(''); var color = '#'; (var = 0; < 6; i++) { color += letters[math.round(math.random() * 15)]; } return color; } $(".post").each(function() { $(this).css('background-color', get_random_color()); });
you need change code bit this:
$(".post").each(function() { var color = get_random_color(); $(this).children("h1, div").css('background-color', color); });
notice can change children selector @ will.
here's working example: http://jsfiddle.net/r74j6/212/
Comments
Post a Comment