SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    What rong with this code?

    Hai all,
    i am trying to change the raw colors of a table.
    whats wrong with this code

    Code:
    function loop1(){
    document.getElementById('1').bgcolor="#00FFFF";
    document.getElementById('2').bgcolor="#FFFFFF";
    document.getElementById('3').bgcolor="#00FFFF";
    document.getElementById('4').bgcolor="#FFFFFF";
    document.getElementById('5').bgcolor="#00FFFF";
    }
    Note : my html table as follows
    Code:
    <table width="400" border="0" align="center">
      <tr id="1">
        <td bgcolor="#00FFFF">&nbsp;</td>
      </tr>
      <tr id="2">
        <td>&nbsp;</td>
      </tr>
      <tr id="3">
        <td>&nbsp;</td>
      </tr>
      <tr id="4">
        <td>&nbsp;</td>
      </tr>
      <tr id="5">
        <td>&nbsp;</td>
      </tr>
    </table>

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's invalid markup. An ID cannot start with a digit. An ID must start with a letter (A-Z, a-z).
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    tx aust....
    Now my table looklike this
    Code:
    <table width="400" border="0" align="center">
      <tr id="a">
        <td>&nbsp;</td>
      </tr>
      <tr id="b">
        <td>&nbsp;</td>
      </tr>
      <tr id="c">
        <td>&nbsp;</td>
      </tr>
      <tr id="d">
        <td>&nbsp;</td>
      </tr>
      <tr id="e">
        <td>&nbsp;</td>
      </tr>
    </table>
    JS Code look like this

    Code:
    function loop2(){
    document.getElementById('a').bgcolor="#FFFFFF";
    document.getElementById('b').bgcolor="#00FFFF";
    document.getElementById('c').bgcolor="#FFFFFF";
    document.getElementById('d').bgcolor="#00FFFF";
    document.getElementById('e').bgcolor="#FFFFFF";
    alert("hai");
    }
    The "hai" message appear. but table raw colors are not changed ?

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this then,
    Code:
    document.getElementById('a').style.backgroundColor = "#FFFFFF";
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    work like a charm !!!
    one more small question austis..
    what is the diffrent between bgcolor and backgroundColor ?

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "bgcolor" attribute is depreciated - "backgroundColor" ("background-color") is a CSS property and is the proper way of giving an element a background colour.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  7. #7
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hai Jimmy,
    Tx a lOt !

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to be nit-picking, but bgcolor is deprecated, not depreciated.
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by AutisticCuckoo View Post
    Sorry to be nit-picking, but bgcolor is deprecated, not depreciated.
    Spell not an issue, Coz am Asian

  10. #10
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's just that the two words mean different things. Deprecated means 'disapproved' or 'urged against', while depreciated means 'of diminishing value'.
    Birnam wood is come to Dunsinane

  11. #11
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops... Sorry about that!
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  12. #12
    Designer
    Join Date
    Jun 2006
    Location
    Manila
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Sorry to be nit-picking, but bgcolor is deprecated, not depreciated.
    Lol. Well, it's not that far off. Something would have to be depreciated (to a certain extent) before it gets deprecated, right?

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think so. I doubt that the bgcolor ever had any inherent value that could be diminished.
    Birnam wood is come to Dunsinane

  14. #14
    Designer
    Join Date
    Jun 2006
    Location
    Manila
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    I don't think so. I doubt that the bgcolor ever had any inherent value that could be diminished.
    I must work at my feeble attempt at humor.

  15. #15
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or I should learn to add a smilie to show that I'm joking in return.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •