Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to Reference a Table Row without using Index?

    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.

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you generate id's for each row, that would probably be one solution..
    e.g.,
    Code:
        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:
    Code:
        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();
        }
    Last edited by fci; 12-31-2005 at 02:16 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •