473,767 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there anything wrong with this SHORT code?

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.getEle mentsByTagName( 'td' );
for (i = 0; i < my_i.length; i++)
{
if ((my_i[i].hasAttribute( 'BGCOLOR' )) && (my_i[i].getAttributeNo de(
'BGCOLOR' ).value == '#F7FFFB' ))
my_i[i].setAttribute( 'BGCOLOR', '#00FF00' );
}

Feb 27 '06 #1
2 1265
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.getEle mentsByTagName( 'td' );
for (i = 0; i < my_i.length; i++)
{


if (my_i[i].style.backgrou ndColor == '#f7fffb')
{
my_i[i].style.backgrou ndColor = '#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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 27 '06 #2
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.getEle mentsByTagName( 'td' );
for (i = 0; i < my_i.length; i++)
{

if (my_i[i].style.backgrou ndColor == '#f7fffb')
{
my_i[i].style.backgrou ndColor = '#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="backgrou nd-color: #f7fffb;" border="1">
<tr>
<td onclick="alert( this.style.back groundColor);">
click to see background color <b>inherited</b> from table
</td>
<td style="backgrou nd-color: #f7fffb;"
onclick="alert( this.style.back groundColor);">
click to see background color set <b>inline</b>
</td>
</tr>
</table>

--
Rob
Feb 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1986
by: Hal Vaughan | last post by:
I am working on an install program, for another program that will need a list of printers on a system. Originally I found the printers by doing this: public PrintNames() { String tName = ""; PrintService pServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Service count: "+pServices.length); cPrinter = new String;
73
8069
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
51
13387
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this wrong????? Function x select case z
2
2169
by: atv | last post by:
Hi, is there something wrong with this code? It seems that it crashes at the else { clause, when allocating a second record. Excuse for the indentation, the g_warnings are from gtk. Also, i'm using 2 pointers in the struct, which consists of 3 ints, and 2 pointers, which i give 256 bytes each. Much to much ofcourse, but it's just testcode. The code doesn't even reach the g_warning in the { code.
8
1638
by: Droopy | last post by:
I am making a managed C++ wrapper for calling legacy C++ code from C#. I don't understand what's wrong with following code : __gc public class SerialBuffer { private: unsigned char __nogc*_buffer; short _bufferNr; bool _isUsed; int _length;
5
1943
by: christian | last post by:
Hi! I have a problem with a template function im MSVC6 the template function is defined as: template <__Type1, __Type2> int MyFunc(int param1, double param2) {__Type1 var1; __Type2 var2; ... do something ...
16
1982
by: msundaram.visvanathan | last post by:
Hi, i tried to write this small code in C which would: Input :a b c d Output:abcd code: #include<stdio.h>
4
1594
by: Landes | last post by:
Hiya, I have the following code in a C# aspx page, but I keep getting the error that 'ExceptionCategoryId_' not found. Looks like the QueryString is not returning anything. <asp:DataGrid id=DataGrid1 runat="server" AutoGenerateColumns="False" DataSource ="<%# Pfc.PfcCentreExceptions.Current.DataSet %>" DataMember ='ExceptionCategoryId_<%=Request.QueryString%>'
22
2039
by: davy.zou | last post by:
I found the code for a program that is suppose to be able to work out the sumation of i from 1 to a certain integer n. however, when I implemented to code into Visual C++, it doesn't work. The original sample code provided by the website: unsigned int Sum (unsigned int n) { unsigned int result = 0; for (unsigned int i=1; i<=n; i++) { result+=1;
3
2974
by: Blue sky | last post by:
Hi,I am a new C++ learner.The follow prgram produces a wrong result,but I can't find the wrong.Can you help me?Thank you! #include<stdio.h> long factorial( long number); int main() { int a;
0
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.