By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

setAttribute('bgcolor') and Internet Explorer

P: n/a
Hello All:

Using javascript to dynamically add row elements to a table.
as in .....
row.setAttribute("bgcolor",rowColor);
// or

cell.setAttribute("bgcolor",rowColor);
Using firefox or netscape I'm seeing colors rendered as I would hope
for. However the same process in Internet Explorer does render the
color.

Before submitting code, it might be useful if I could look at some
documentation on the subject of discrepancies between IE and other
browsers. Pointers to such documentation is being solicited!

Thanks
Tim
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Tim Johnson wrote:
Hello All:

Using javascript to dynamically add row elements to a table.
as in .....
row.setAttribute("bgcolor",rowColor);
// or

cell.setAttribute("bgcolor",rowColor);
Do you mean add rows or change row attributes? 'bgcolor' is
depreciated, you should be using the row's style object or CSS rule
(say by adding a class).

row.style.backgroundColor = rowColor;

or

row.className = 'someClass';

Providing you've done feature detection to ensure that the style
object is supported first.
Using firefox or netscape I'm seeing colors rendered as I would hope
for. However the same process in Internet Explorer does render the
color.
? So you don't have any problems? Or does IE *not* render the
colour? :-o
Before submitting code, it might be useful if I could look at some
documentation on the subject of discrepancies between IE and other
browsers. Pointers to such documentation is being solicited!


Sorry, don't have any. :-(

--
Rob
Jul 23 '05 #2

P: n/a
Jc
Tim Johnson wrote:
<snip>
Before submitting code, it might be useful if I could look at some
documentation on the subject of discrepancies between IE and other
browsers. Pointers to such documentation is being solicited!


Here's one: http://www.quirksmode.org/

Jul 23 '05 #3

P: n/a


Tim Johnson wrote:

Using javascript to dynamically add row elements to a table.
as in .....
row.setAttribute("bgcolor",rowColor);
// or

cell.setAttribute("bgcolor",rowColor);


Consider using
cell.bgColor = ...
or if you want to use setAttribute then take notice that with IE the
attribute name is case sensitive so
cell.setAttribute("bgColor", ...)
is what you need.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

P: n/a
RobG wrote:
Tim Johnson wrote:
Hello All:

Using javascript to dynamically add row elements to a table.
as in .....
row.setAttribute("bgcolor",rowColor);
// or

cell.setAttribute("bgcolor",rowColor);

Do you mean add rows or change row attributes? 'bgcolor' is
depreciated, you should be using the row's style object or CSS rule
(say by adding a class).

row.style.backgroundColor = rowColor;

or

row.className = 'someClass';


Aha!
Providing you've done feature detection to ensure that the style
object is supported first.


Sorry. I am ignorant of "feature detection". <duh>
Can you point me to a HOWTO on feature detection?
Using firefox or netscape I'm seeing colors rendered as I would hope
for. However the same process in Internet Explorer does render the
color.

? So you don't have any problems? Or does IE *not* render the
colour? :-o


Type there. IE does *not* render the color. Will try your code
revisions above.
Thanks very much.
cheers
tim
Before submitting code, it might be useful if I could look at some
documentation on the subject of discrepancies between IE and other
browsers. Pointers to such documentation is being solicited!

Sorry, don't have any. :-(

Jul 23 '05 #5

P: n/a
Martin Honnen wrote:


Tim Johnson wrote:

Using javascript to dynamically add row elements to a table.
as in .....
row.setAttribute("bgcolor",rowColor);
// or

cell.setAttribute("bgcolor",rowColor);

Consider using
cell.bgColor = ...
or if you want to use setAttribute then take notice that with IE the
attribute name is case sensitive so
cell.setAttribute("bgColor", ...)
is what you need.

In this case, it turns out that just changing the string to
"bgColor" (upcase "C") did the trick, but I am mindful of Rob's
advice about using the style object or 'className. I'd like this
to be "forward compatible" regards IE, and perhaps in the future
IE will disregard the 'bgColor' attribute for setAttribute()?

Thanks
tim
Jul 23 '05 #6

P: n/a
Tim Johnson wrote:
RobG wrote:

[...]
Do you mean add rows or change row attributes? 'bgcolor' is
depreciated, you should be using the row's style object or CSS rule
(say by adding a class).

row.style.backgroundColor = rowColor;

or

row.className = 'someClass';

Aha!
Providing you've done feature detection to ensure that the style
object is supported first.

Sorry. I am ignorant of "feature detection". <duh>
Can you point me to a HOWTO on feature detection?


Feature detection is checking to see that a particular feature is
available before trying to use it. Check once and then subsequent code
should operate depending on whether the feature is available or not.

The trivial test in this case would be:

if ( row.style ) {
row.style.backgroundColor = rowColor;
} else if ( row.setAttribute ) {
row.setAttribute("bgColor",rowColor);
} else {
// account neither being supported
}

But I would think that any browser supporting one will (most likely)
support the other (they are both in DOM 2). The difference is that
setAttribute changes an attribute of the element (hence bgColor, which
is a depreciated attribute of the row element) rather than the style
object associated with the element (i.e. style.backgroundColor, which
uses the 'new hotness' - CSS).

setAttribute has issues when used for setting an onclick event, the
implementation in IE differs from other browsers.

<URL:http://groups-beta.google.com/group/comp.lang.javascript/browse_frm/thread/2878063f9bb87888/03e84aca31e90290?tvc=1&q=setAttribute+style&hl=en# 03e84aca31e90290>

It just seems that if there is a 'future proof', cross-browser
solution, why not use it? It also looks neater :-)

--
Rob
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.