Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Thursday, September 25, 2014

JQuery Change Div Background Color Randomly

How to change background color of div by JQuery:



In this post we explain randomly change the back ground color of div at run time.

JQuery Function of change background:

function changecolor() {
        var colors = ["#B40404", "#0000FF", "#FE2E9A", "#FF0080", "#2EFE2E", ];
        var rand = Math.floor(Math.random() * colors.length);
        $('#controls-wrapper').css("background-color", colors[rand]);
        setTimeout('changecolor()', 1000);
    }

JQuery Related Other Post:


JQuery Example of change background:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="divExample.aspx.cs" Inherits="divExample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        changecolor();
    });
    function changecolor() {
        var colors = ["#B40404", "#0000FF", "#FE2E9A", "#FF0080", "#2EFE2E", ];
        var rand = Math.floor(Math.random() * colors.length);
        $('#controls-wrapper').css("background-color", colors[rand]);
        setTimeout('changecolor()', 1000);
    }
</script>
    <style type="text/css">
        .style1
        {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<form id="form1" runat="server">
<div id="controls-wrapper" align="center">
<p>
<h1><span class="style1">Hello </span> <br class="style1" />
    <span class="style1">Friends </span> </h1>
welcome to this <a href="http://asp-net-by-parijat.blogspot.in/">Asp.net tutorial.</a><br />
    <br />
    <br />
    <br />
&nbsp;</p>
</div>
</form>
</body>
</html>



Other Examples:


No comments:

Post a Comment