Advanced javascript

Discussion in 'JavaScript' started by cancer10, Jun 27, 2008.

  1. #1
    I have a table. the first table document has a welcome text and the last td has a hyperlink. Is there anyway I can prompt an alert with the text thats on the first td?

    Note: there are no IDs/class for the table td in this case.


    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>welcome to my site</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href>Clicky</a></td>
      </tr>
    </table>
    Code (markup):
     
    cancer10, Jun 27, 2008 IP
  2. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    oops sorry dint read about the id, ignore my post :)
     
    sharry, Jun 27, 2008 IP
  3. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Remember, there is no id or class in the table?
     
    cancer10, Jun 27, 2008 IP
  4. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes i posted a code with id, removed it now
     
    sharry, Jun 27, 2008 IP
  5. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You may try
     
    koolman, Jun 27, 2008 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If its the first td in the whole page use:

    alert(document.getElementsByTagName("td")[0].innerHTML);
     
    MMJ, Jun 27, 2008 IP
    sharry likes this.
  7. yankzilla

    yankzilla Peon

    Messages:
    159
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I agree with him. That's what I was going to suggest, was just fetching the first td in the page. Or if it's not, then find out which one it is, and change the number accordingly.
     
    yankzilla, Jun 27, 2008 IP