...

View Full Version : How to Reference a Table Row without using Index?



dealmaker
12-31-2005, 01:40 AM
Hi,
I need to reference specific rows in a table without using row index because my table is sortable, so row is useless because it can change anytime. Is there a way to reference it using name or id? Is there a better way? I don't want to use a different id for each row.

Many thanks.

fci
12-31-2005, 02:07 AM
if you generate id's for each row, that would probably be one solution..
e.g.,


var trs = document.getElementById('my_table').getElementsByTagName('tr');
var len = trs.length;
while (len-->0)
trs[len].id = 'uniq_' + len;


so then if it is sorted, you wouldn't lose the unique id assigned to it.

you could also try comparing nodes for equality but eh.. that doesn't sound right

maybe something like this, don't know enough about your problem though:


var trs = document.getElementById('my_table').getElementsByTagName('tr');
var len = trs.length;
var saveme = [];
while (len-->0) {
if (condition) saveme.push(trs[len]);
}
// then later on
var len = saveme.length;
while (len-->0) {
saveme[len].doSomething();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum