Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is there anything wrong with this SHORT code?

Reply
Thread Tools

Is there anything wrong with this SHORT code?

 
 
Alex
Guest
Posts: n/a
 
      02-27-2006
Trying to change a few tags by swapping color values to my own. It
doesn't give any error, yet it doesn't perform. Is there an error in my
logic somewhere?

var my_i = document.getElementsByTagName( 'td' );
for (i = 0; i < my_i.length; i++)
{
if ((my_i[i].hasAttribute( 'BGCOLOR' )) && (my_i[i].getAttributeNode(
'BGCOLOR' ).value == '#F7FFFB' ))
my_i[i].setAttribute( 'BGCOLOR', '#00FF00' );
}

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      02-27-2006
Alex said the following on 2/27/2006 12:34 AM:
> Trying to change a few tags by swapping color values to my own. It
> doesn't give any error, yet it doesn't perform. Is there an error in my
> logic somewhere?
>
> var my_i = document.getElementsByTagName( 'td' );
> for (i = 0; i < my_i.length; i++)
> {


if (my_i[i].style.backgroundColor == '#f7fffb')
{
my_i[i].style.backgroundColor = '#00ff00';
}

You may want to use toLowerCase() on the backgroundColor if you are not
sure of the Case of the color codes.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      02-27-2006
Randy Webb wrote:
> Alex said the following on 2/27/2006 12:34 AM:
>
>> Trying to change a few tags by swapping color values to my own. It
>> doesn't give any error, yet it doesn't perform. Is there an error in my
>> logic somewhere?
>>
>> var my_i = document.getElementsByTagName( 'td' );
>> for (i = 0; i < my_i.length; i++)
>> {

>
>
> if (my_i[i].style.backgroundColor == '#f7fffb')
> {
> my_i[i].style.backgroundColor = '#00ff00';
> }
>
> You may want to use toLowerCase() on the backgroundColor if you are not
> sure of the Case of the color codes.
>


Probably worth pointing out to the OP that this will read the background
colour of the TD style object, not the colour inherited through a CSS
stylesheet rule or other declaration.

e.g.

<table style="background-color: #f7fffb;" border="1">
<tr>
<td onclick="alert(this.style.backgroundColor);">
click to see background color <b>inherited</b> from table
</td>
<td style="background-color: #f7fffb;"
onclick="alert(this.style.backgroundColor);">
click to see background color set <b>inline</b>
</td>
</tr>
</table>

--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there anything fundamentally wrong with this code? simon.stockton@baesystems.com VHDL 5 04-20-2006 01:09 PM
brut force eigrp over gre working, is there anything wrong? jcharth@hotmail.com Cisco 0 10-05-2005 09:57 PM
Is there anything wrong with the following ? Roubles C Programming 3 05-14-2004 09:22 PM
Is there anything wrong with my insert code? Mano kumar ASP .Net 2 10-17-2003 01:51 PM
Re: Is there anything wrong... rf HTML 1 07-06-2003 11:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57