473,473 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to blink two colors in table td using JS?

3 New Member
Hi,

I need to use e.getelementsbytagname to pull background color and make it blink every one minute in table cell td between two colors.

Any help would be awesome!
Feb 15 '10 #1
9 9208
Dormilich
8,658 Recognized Expert Moderator Expert
what do you have so far?
Feb 15 '10 #2
bbQsauce
3 New Member
I have this so far:

html:

Expand|Select|Wrap|Line Numbers
  1.   <tr class='bus'>
  2.    <td>Europe</td>
  3.    <td>EU111</td>
  4.    <td title='One'>Country</td>
  5.    <td class='b_number'>1457</td>
  6.    <td class='notice'>Bus left</td>
  7.   </tr>
I want to make it so class='notice' td changes background color every 1min between two colors i define.

I think it should be simple few lines using e.getElementsByTagName() just not sure how to construct it.
Feb 15 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
I think it should be simple few lines using e.getElementsByTagName() just not sure how to construct it.
why so difficult? you already have a class, thus document.getElementsByClassName() (ok, not in IE) should do the job.

already an idea, how to get the timing working?
Feb 15 '10 #4
bbQsauce
3 New Member
I would need this to be done by td not by class.. would it be something like:

Expand|Select|Wrap|Line Numbers
  1. var table = document.getElementsByClassName('notice')  
  2. var cells = table.getElementsByTagName("td"); 
  3.   for (var i = 0; i < cells.length; i++) { 
  4.     status = cells[i].getAttribute("status"); 
  5.     if ( status == "open")  
  6.        cells[i].getElementsByTagName('td').style.color='white';
  7.     else
  8.        cells[i].getElementsByTagName('td').style.color='black'; 
  9. }
  10.  
Feb 15 '10 #5
zorgi
431 Recognized Expert Contributor
I saw this problem and strait away i thought jQuery

This is how it can be done with jQuery:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="jquery.js"></script>
  2. <script type="text/javascript">
  3.  
  4. $(function(){blinkOn()})
  5.  
  6. function blinkOn(){
  7.     $(".notice").css("background-color", "red");
  8.     setTimeout("blinkOff()", 2000);
  9. }
  10.  
  11. function blinkOff(){
  12.     $(".notice").css("background-color", "white");
  13.     setTimeout("blinkOn()", 60000);
  14. }
  15. </script>
  16.  
This example blinks red every 60 seconds for 2 seconds.
Feb 15 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
note:
Expand|Select|Wrap|Line Numbers
  1. setTimeout(blinkOff, 2000);
Feb 15 '10 #7
zorgi
431 Recognized Expert Contributor
Thanks Dorm

Slightly more compact solution:
Expand|Select|Wrap|Line Numbers
  1. $(function(){blinkOn(2000, 'red');})
  2. function blinkOn(time, color){
  3.     $(".notice").css("background-color", color);    
  4.     switch(time){
  5.         case 2000:
  6.             setTimeout("blinkOn(60000, 'white')", time);
  7.             break;
  8.         default:
  9.             setTimeout("blinkOn(2000, 'red')", time);            
  10.     }
  11. }
  12.  
Feb 15 '10 #8
zorgi
431 Recognized Expert Contributor
aaaand one more :)
Expand|Select|Wrap|Line Numbers
  1. $(function(){
  2.     time = 2000;
  3.     color = 'white';           
  4.     setInterval(function(){
  5.                             $(".notice").css("background-color", color);
  6.                             switch(time){
  7.                                 case 2000:
  8.                                     time = 60000;
  9.                                     color = 'red';
  10.                                     break;
  11.                                 default:
  12.                                     time = 2000;
  13.                                     color = 'white';
  14.                             }                        
  15.                         }, time);           
  16. })
  17.  
Spoiled for choice :)
Feb 16 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
aaaand one more note:
Expand|Select|Wrap|Line Numbers
  1. setTimeout(blinkOn, time, 60000, 'white');
just to have it mentioned
Feb 16 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: LVande | last post by:
SQLLY challenged be gentle -- Trying to create code that will drop a table using a variable as the Table Name. DECLARE @testname as char(50) SELECT @testname = 'CO_Line_of_Business_' +...
2
by: Ralph Snart | last post by:
Is there a way to alternate table row colors without using the position() mod 2 trick? I'm in a series of nested xsl:for-each elements, about 3 deep, and I want to alternate the table row color...
4
by: Andre Arpin | last post by:
I am new at sql so would appreciate some help I have the name of a table in alocal variable is it possible to select this table DECLARE @name sysname SET @name = 'tblSniffedItems' PRINT...
2
by: Max | last post by:
Hi, I have the following problem. I want to insert records into one table using the combination of two other tables. Here is a simplified example: Let's say the first table has a column with...
4
by: dave | last post by:
I need to add a column to a table using code. The following works, but only for a new table. How should I change this to alter an existing table? Dim strConn Dim Catalog As New...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
4
by: Nathan Sokalski | last post by:
When editing an ASP Table, Visual Studio does not allow me to edit it in Design View. This makes it harder to add elements, because I must add every element either by using Design View to create...
2
by: Laphan | last post by:
AAAAARRRRGGGGHHHH!!! Everything appears to be great in doing a web-based editor using the execCommands apart from the fact that there is no method to insert a table. I've seen somebody suggest...
0
by: cb123 | last post by:
Hello, Please bear with me I'm new to t-sql. I've had no luck trying to figure this out yet using sql code. I need to use an existing table (data dictionary) as input for creating a new table. ...
13
nabh4u
by: nabh4u | last post by:
hi, I am trying to insert multiple rows in a table using PL/SQL. I have two procedures and two tables. the first procedure gets the data from the source table, manipulates it and then sends the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.