javascript - Random generated colors and saving them in CSS -


i'm won't able explain 100% because if figure out.

i'm trying code chat room. want use javascript randomly generate color , assign someone's name. assign once , when type new message defaults. how make color sticks? have far:

$(document).ready(function() { $('.username').each(function () {     var hue = 'rgb(' + (math.floor((256-199)*math.random()) + 200) + ',' + (math.floor((256-199)*math.random()) + 200) + ',' + (math.floor((256-199)*math.random()) + 200) + ')';     $(".username").css("color", hue); }); }); 

try using $(this) instead of $(".username") inside each function:

$('.username').each(function () {     var hue = 'rgb(' + (math.floor((256-199)*math.random()) + 200) + ',' + (math.floor((256-199)*math.random()) + 200) + ',' + (math.floor((256-199)*math.random()) + 200) + ')';     $(this).css("color", hue); }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -