Jump to content

Rowindex Dom Shorthand


geomagnet

Recommended Posts

I have a table with many elements, so to get to the row element allowing me to use the rowIndex method I get a really ugly statement:alert(objID(objName).parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);Is there a better way to do this...perhaps something like:alert(objID(objName).parentNode(*9).rowIndex); or alert(objID('table_in_question').rowIndex);Thanks

Link to comment
Share on other sites

this little routine will do the trick.

<table>	<tr><td onclick="getRowIndex(this)">R1C1</td><td><span><div onclick="getRowIndex(this)">R1C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R2C1</td><td><span><div onclick="getRowIndex(this)">R2C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R3C1</td><td><span><div onclick="getRowIndex(this)">R3C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R4C1</td><td><span><div onclick="getRowIndex(this)">R4C2</div></span></tr></table><script>		function getRowIndex(object)		{			while (object.tagName != 'TR')			{				object = object.parentNode			}			alert (object.rowIndex)		}</script>

Link to comment
Share on other sites

this little routine will do the trick.
<table>	<tr><td onclick="getRowIndex(this)">R1C1</td><td><span><div onclick="getRowIndex(this)">R1C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R2C1</td><td><span><div onclick="getRowIndex(this)">R2C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R3C1</td><td><span><div onclick="getRowIndex(this)">R3C2</div></span></tr>	<tr><td onclick="getRowIndex(this)">R4C1</td><td><span><div onclick="getRowIndex(this)">R4C2</div></span></tr></table><script>		function getRowIndex(object)		{			while (object.tagName != 'TR')			{				object = object.parentNode			}			alert (object.rowIndex)		}</script>

Cool, that looks like a good solution for one table.How would you get this to work for nested tables and page with multiple tables?for instance:
<table id="table_1"><tr><td> stuff</td><tr><tr><td> stuff</td><tr><tr><td> stuff</td><tr><tr><td> stuff</td><tr><tr><td> stuff</td><tr><tr><td> [indent]  <table id = "table_2"><tr><td> stuff</td><tr> <tr><td> stuff</td><tr><tr><td> stuff</td><tr><tr><td> stuff</td><tr>[/indent]</table></td><tr></table>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...