mrpbennett
1/10/2017 - 11:46 AM

Set a random background color to and element

Set a random background color to and element

function setbgColor(){
	var r = Math.floor(Math.random() * 256);
	var g = Math.floor(Math.random() * 256);
	var b = Math.floor(Math.random() * 256);

	var obj = document.getElementById('id');

	if(obj){
		obj.style.background = 'rgb(' + r + ',' + g + ',' + b + ')';
	}
}