Jump to content

Rowindex Dom Shorthand


geomagnet
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...