Tuesday, December 10, 2013

How to Autoloop in Jquery?

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

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function () {

$('p').css("background-color", "yellow");

var cnt = $("p").length;

var i = cnt * 1000;



setInterval(abc, i);

});

function abc() {





$("p").each(function (index) {

var self = this

setTimeout(function () {

$('p').css("background-color", "yellow");

$(self).css("background-color", "Red");



}, index * 1000);

});

}







</script>

<style type="text/css">

.RED{ background-color: Red;}

.GREEN{ background-color: Green;}

</style>

</head>

<body>

<form id="form1" runat="server">

<table>

<tr>

<td>

<p>

1</p>

</td>

<td>

<p>

2</p>

</td>

<td>

<p>

3</p>

</td>

<td>

<p>

4</p>

</td>

<td>

<p>

5</p>

</td>

<td>

<p>

6</p>

</td>

<td>

<p>

7</p>

</td>

<td>

<p>

8</p>

</td>

</tr>

</table>





</form>

</body>

</html>

1 comment:

  1. see link for string formats: http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx

    ReplyDelete