Javascript detect row number of table

Is there any way to detect what row in a table that a user clicked on?  I have a table with regular html buttons (<button id="1"> 2,3,4 ect.) in it.  I have a function that deletes the rows from the table when the user clicks on the button.  But after it deletes the row the row numbers change.  Is there anyway to detect what row the button, or anything for that matter, is in so users can delete more than one row?
johnywhiteAsked:
Who is Participating?
 
0h4crying0utloudCommented:

The "this.parentNode.parentNode" return the row obj that contains the button that was clicked. Does that help?

<table>
  <tr id="1strow">
    <td><input type="button" onclick="alert(this.parentNode.parentNode.id)" value="test me"></td>
  </tr>
</table>
0
 
0h4crying0utloudCommented:


Did you need more help with this?
0
 
johnywhiteAuthor Commented:
That doesn't seem to be working it doesn't return anything.  It doesn't give an error either.  Could you post a working page that shows this as an example.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
johnywhiteAuthor Commented:
I understand it.  I have to have the row id, however, the deleteRow command only accepts the indexnumber of the row.  Is there anyway to either return the index number or delete a row by it's id?
0
 
johnywhiteAuthor Commented:
I just figured it out it is this.parentNode.parentNode.rowIndex instead.  Thanks for your help!
0
 
0h4crying0utloudCommented:

Yeah, that's right, you dont even need the rowID. Glad to Help!

Cheers!
-Vinson Gracia
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.