setAttribute('bgcolor') and Internet Explorer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Johnson

    setAttribute('bgcolor') and Internet Explorer

    Hello All:

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

    cell.setAttribu te("bgcolor",ro wColor);
    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
  • RobG

    #2
    Re: setAttribute('b gcolor') and Internet Explorer

    Tim Johnson wrote:[color=blue]
    > Hello All:
    >
    > Using javascript to dynamically add row elements to a table.
    > as in .....
    > row.setAttribut e("bgcolor",row Color);
    > // or
    >
    > cell.setAttribu te("bgcolor",ro wColor);[/color]

    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.backg roundColor = rowColor;

    or

    row.className = 'someClass';

    Providing you've done feature detection to ensure that the style
    object is supported first.
    [color=blue]
    > 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.[/color]

    ? So you don't have any problems? Or does IE *not* render the
    colour? :-o
    [color=blue]
    > 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![/color]

    Sorry, don't have any. :-(

    --
    Rob

    Comment

    • Jc

      #3
      Re: setAttribute('b gcolor') and Internet Explorer

      Tim Johnson wrote:
      <snip>[color=blue]
      > 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![/color]

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

      Comment

      • Martin Honnen

        #4
        Re: setAttribute('b gcolor') and Internet Explorer



        Tim Johnson wrote:

        [color=blue]
        > Using javascript to dynamically add row elements to a table.
        > as in .....
        > row.setAttribut e("bgcolor",row Color);
        > // or
        >
        > cell.setAttribu te("bgcolor",ro wColor);[/color]

        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.setAttribu te("bgColor", ...)
        is what you need.

        --

        Martin Honnen

        Comment

        • Tim Johnson

          #5
          Re: setAttribute('b gcolor') and Internet Explorer

          RobG wrote:[color=blue]
          > Tim Johnson wrote:
          >[color=green]
          >> Hello All:
          >>
          >> Using javascript to dynamically add row elements to a table.
          >> as in .....
          >> row.setAttribut e("bgcolor",row Color);
          >> // or
          >>
          >> cell.setAttribu te("bgcolor",ro wColor);[/color]
          >
          >
          > 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.backg roundColor = rowColor;
          >
          > or
          >
          > row.className = 'someClass';[/color]

          Aha!
          [color=blue]
          > Providing you've done feature detection to ensure that the style
          > object is supported first.[/color]

          Sorry. I am ignorant of "feature detection". <duh>
          Can you point me to a HOWTO on feature detection?
          [color=blue][color=green]
          >> 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.[/color]
          >
          >
          > ? So you don't have any problems? Or does IE *not* render the
          > colour? :-o[/color]

          Type there. IE does *not* render the color. Will try your code
          revisions above.
          Thanks very much.
          cheers
          tim
          [color=blue][color=green]
          >> 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![/color]
          >
          >
          > Sorry, don't have any. :-(
          >[/color]

          Comment

          • Tim Johnson

            #6
            Re: setAttribute('b gcolor') and Internet Explorer

            Martin Honnen wrote:[color=blue]
            >
            >
            > Tim Johnson wrote:
            >
            >[color=green]
            >> Using javascript to dynamically add row elements to a table.
            >> as in .....
            >> row.setAttribut e("bgcolor",row Color);
            >> // or
            >>
            >> cell.setAttribu te("bgcolor",ro wColor);[/color]
            >
            >
            > 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.setAttribu te("bgColor", ...)
            > is what you need.[/color]
            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

            Comment

            • RobG

              #7
              Re: setAttribute('b gcolor') and Internet Explorer

              Tim Johnson wrote:[color=blue]
              > RobG wrote:[/color]
              [...][color=blue][color=green]
              >> 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.backg roundColor = rowColor;
              >>
              >> or
              >>
              >> row.className = 'someClass';[/color]
              >
              >
              > Aha!
              >[color=green]
              >> Providing you've done feature detection to ensure that the style
              >> object is supported first.[/color]
              >
              >
              > Sorry. I am ignorant of "feature detection". <duh>
              > Can you point me to a HOWTO on feature detection?
              >[/color]

              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.backg roundColor = rowColor;
              } else if ( row.setAttribut e ) {
              row.setAttribut e("bgColor",row Color);
              } 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.backgroun dColor, 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.javas cript/browse_frm/thread/2878063f9bb8788 8/03e84aca31e9029 0?tvc=1&q=setAt tribute+style&h l=en#03e84aca31 e90290>

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



              --
              Rob

              Comment

              Working...