table cell properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Madsen

    table cell properties

    I am trying to learn JavaScript--(complete newbie--and don't know C or
    C++). I've been reading "The Book of JavaScript" by Thau.

    I don't see anything about table properties in the book. (I would like
    to try to write a script so that the background color in a cell in a
    table changes color (between two or three specified colors)). How do I
    get at the background color property in a table cell?

    Sorry for such a basic question.

    Jim

  • Andy Fish

    #2
    Re: table cell properties

    to program javascript in a web page, you need to know there is a difference
    between javascript the language and "DOM" the document object model

    the latter is the thing that specifies the different types of objects you
    find in a web page and how to change them programmaticall y - see


    I don't know the answer to your specific question, but this is where to
    look. It will help you in the long run if you get familiar with navigating
    the DOM specifications

    Andy

    "Jim Madsen" <jemadsen@nospa madelphia.net> wrote in message
    news:3F401342.6 030806@nospamad elphia.net...[color=blue]
    > I am trying to learn JavaScript--(complete newbie--and don't know C or
    > C++). I've been reading "The Book of JavaScript" by Thau.
    >
    > I don't see anything about table properties in the book. (I would like
    > to try to write a script so that the background color in a cell in a
    > table changes color (between two or three specified colors)). How do I
    > get at the background color property in a table cell?
    >
    > Sorry for such a basic question.
    >
    > Jim
    >[/color]


    Comment

    • Yep

      #3
      Re: table cell properties

      Jim Madsen <jemadsen@nospa madelphia.net> wrote in message news:<3F401342. 6030806@nospama delphia.net>...
      [color=blue]
      > I don't see anything about table properties in the book. (I would like
      > to try to write a script so that the background color in a cell in a
      > table changes color (between two or three specified colors)). How do I
      > get at the background color property in a table cell?[/color]

      DOM objects expose a "style" object property, which offers many useful
      properties to affect the style of the object. For your issue, you'd
      have something like

      document.getEle mentById("MyCel l").style.backg roundColor = "blue";

      Check the CSS specification at W3C for all style properties.


      HTH
      Yep.


      <style type="text/css">
      td {background-color:black; width:1em;}
      </style>

      <script type="text/javascript">
      var s="I love javascript!";
      var html="<table><t r>";
      for(var ii=0; ii<s.length; ii++)
      html+="<td id='td"+ii+"'>" +s.charAt(ii)+" <\/td>";
      html+="<\/tr><\/table>"
      document.write( html);

      setTimeout(
      function() {
      var index = 0, d=document;
      function nextIndex() {
      if(++index>s.le ngth-1) return(index=0) ;
      return index;
      }
      return function() {
      if(d.getElement ById) {
      d.getElementByI d("td"+index).s tyle.background Color="black";
      d.getElementByI d("td"+nextInde x()).style.back groundColor="ye llow";
      setTimeout(argu ments.callee, 300);
      }
      }
      }(),
      50
      );
      </script>

      Comment

      Working...