Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the background color randomly with the Javascript?

I want to change the background colour once the user refresh the page

like image 442
Saif Abushama Avatar asked Dec 02 '25 23:12

Saif Abushama


1 Answers

You can do it by jQuery, Please check the code below :

$(document).ready(function() {
var randomColor = Math.floor(Math.random()*16777215).toString(16);
    $("#background").css("background-color", '#' + randomColor);
});
like image 187
Alaa Mohammad Avatar answered Dec 04 '25 12:12

Alaa Mohammad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!