Jump to content

get the innerHTML of a td when passing 'this' and table id


freelance84

Recommended Posts

 

This function simply removes a table row:

The HTML:

<td>
    <input type="button" value="X" onclick="deleteRow(this,'myTable');"/>
</td>

 

The js function

function deleteRow(r,tableID){
	var i=r.parentNode.parentNode.rowIndex;
		document.getElementById(tableID).deleteRow(i);
}

 

 

I am trying to write another function which will get the innerHTML of the 1st table cell in the same row, but not sure how. I found this thread on google : thread and this thread

 

But they all seem to cycle through the whole table.

 

Again, this is a new area for me so any pointers to a good tutorial would be awesome if you know any... or how to do it even better  :)

 

Awesome, thanks for the link. Rearranged to this:

 

HTML:

onclick="getRow('theURLTable',this,'0');"

 

the JS

	function getRow(tableID,thisRow,cellNumber){
	var i=thisRow.parentNode.parentNode.rowIndex;

	var x=document.getElementById(tableID).rows[i].cells;

	alert(x[cellNumber].innerHTML);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.