www.webdeveloper.com
Results 1 to 4 of 4

Thread: need help to click link in the table with javascript

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    need help to click link in the table with javascript

    Hello Everybody,
    This is my first post and I know very little in javascript.
    here is my question
    i have table like below with many rows.
    Code:
    <table>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <table>
    and i want use javascript to click the link inside that table, how can i do that?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    you need to set the id attribute to that link and then put this code somewhere below the table

    Code:
    <script>
    document.getElementById('here_goes_the_link_id').click();
    </script>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Nov 2013
    Posts
    2
    thank for your reply,
    what if i have bunch of rows like below
    <table>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <tr>
    <td><a href="some link"></td>
    <tr>
    <table>

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,391
    What do you need the JS to do. Not really needed for this problem...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Untitled </title>
    
    </head>
    <body>
    <table>
    <tr>
    <td><a href="http://www.webdeveloper.com">Webdeveloper</td>
    <tr>
    <tr>
    <td><a href="http://www.codingforums.com">Codingforums</td>
    <tr>
    <tr>
    <td><a href="http://www.dreamincode.net">DreamInCode</td>
    <tr>
    <tr>
    <td><a href="http://bytes.com/topic/javascript/answers/">Bytes</td>
    <tr>
    <table> 
    </body>
    </html>
    Note: You should enclose your code between [ code] and [ /code] tags (without the spaces)
    to set it apart from your comments as I have done above.
    Makes it easier to read and preserves the formatting as well.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles