www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to get the current row clicked in javascript

  1. #1
    Join Date
    May 2012
    Posts
    37

    How to get the current row clicked in javascript

    Hi ,

    I have a html table with some rows. Each row has a 'remove row' button in the end as <td>.
    Now I want that corresponding row to be deleted if the 'remove row' button is clicked.
    Let us consider the table name is "mytable"

    The code is like :

    Code:
    <td> <input type = 'button' value = 'remove row' onclick = remRow() name = remove_i > </td>
    
    function remRow()
    {
    
      document.getElementById("mytable").deleteRow(3);
    
    }
    Right now, I passed hard-coded value '3' to deleteRow in order to delete the third row. But how can I dynamically get the row number as and when a row is clicked and delete it.

    Please help. Thanks.

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    At first change your td tag with a onclick = remRow(this)
    Then change your function like this
    Code:
    function remRow(t){var cl=t.parentNode;
    	alert(cl+' : '+cl.nodeName)
    }
    Finally see this page HTML DOM Table Object to walk through the DOM tree...

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