document.getElementById Help!!!

Discussion in 'JavaScript' started by sanjayc, May 14, 2007.

  1. #1
    The above code changes the content of an element on the page, I have tried it in FireFox and it behaves perfectly, however, try it in Internet Explorer and it falls over.

    Anyone have any ideas how to get around this in IE?

    I'm slowly going crazy!!!

    Thanks
     
    sanjayc, May 14, 2007 IP
  2. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <html>
    <body>
    <table>
    <tr>
    <td id="1">Before</td>
    </tr>
    <tr>
    <td>
    <a href="#" onClick="document.getElementById('1').innerHTML='After'; return false;">Change</a>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Code (markup):
     
    bosko, May 14, 2007 IP
  3. Aztral

    Aztral Well-Known Member

    Messages:
    344
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    125
    #3
    getElementById('1') is a <tr> ? like <tr id='1'>?
     
    Aztral, May 16, 2007 IP
  4. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Try adding a <tbody> tag for that table. It should work.
     
    bibel, May 17, 2007 IP
  5. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There's no need for that. The code bosko posted should work.
     
    Felu, May 17, 2007 IP
  6. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #6
    I'm thinking since he want's to change the innerHTML of a <tr> instead of a <td>, he must have a reason.
    He must have thought it's possible to use <td> instead of <tr> ....
     
    bibel, May 17, 2007 IP
  7. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #7
    innerHTML for TR can too be done.
    <html>
    <body>
    <table>
    <tr id="1">
    <td>Before</td>
    </tr>
    <tr>
    <td>
    <a href="#" onClick="document.getElementById('1').innerHTML='<td>After</td>'; return false;">Change</a>
    </td>
    </tr>
    </table>
    </body>
    </html>
    
    Code (markup):
     
    Felu, May 17, 2007 IP
  8. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The reason I've changed id to td because tr id won't work in IE. So the code Felu posted is not working in IE....
     
    bosko, May 17, 2007 IP
  9. sanjayc

    sanjayc Guest

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for all the responses folks, I have figured it out. You can see the final 'digg spy' like product at http://www.in4matrix.co.uk/spy

    Thanks
    Sanjay
     
    sanjayc, May 17, 2007 IP