Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Generate Random Colors in JavaScript | Random Color Generator in JavaScript

Feb 5, 2013
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 JavaScript in 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

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Anonymous said...

blog has lot of information.... gud methodolgy

about said...

Try your methrod, but the color can not be changed.

vishwanath mali said...

nic

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.