V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2019 Application Form 2019 Colleges Entrance Exam 2019 Results 2019 Notification 2019 University Educational Jobs 2019 Government Jobs 2019

Search This Blog v24s guys

03 April, 2013

Generate Random Colors in JavaScript | Random Color Generator in JavaScript

Introduction

Here I will explain how to generate random colors for div using JavaScript and change color of div at regular intervals of time using JavaScript in asp.net.

Description: 
   
In previous articles I explained 
jQuery Change background color of div, jQuery fadein fadeout effect,jQuery get current page url and title, jQuery create rounded corners for textbox and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to generate random colors for div using JavaScriptin asp.net.
To implement this we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Generate Random Colors using javascript</title>
<script type="text/javascript">
// Run function for every second of timer
setInterval(rgbcolors, 1000);
function rgbcolors() {
// rgb string generation
var col = "rgb("
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ")";
//change the text color with the new random color
document.getElementById("divstyle").style.color = col;
}
</script>
</head>s
<body>
<form id="form1" runat="server" >
<div id="divstyle" style="font:bold 24px verdana">Aspdotnet-suresh.com</div>
</form>
</body>
</html>
Live Demo

For live demo check below div text


Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com Welcome to Aspdotnet-Suresh.comWelcome to Aspdotnet-Suresh.com

No comments:

Popular Posts

Recent Posts

Google Analytics