[BNM] jquery traversing help!

paul perrin paul at idltd.com
Wed Oct 1 12:03:38 BST 2008


Bit new to jquery but...

I would look at adding the ID to the TR (after all it is the entire row that
is dependent on the key), and then use

$(this).parents("tr:first").attr("id")
Haven't tried it - but if I understand the docs it would work - it should
drill up to the the first tr parent element and then return its id... If you
start nesting your tables you are on your own :-) because it drills up this
could be on any element with in the table row (even an anchor in a span in a
td etc...)

parents seems to return in reverse order, so first should be the nearest
tr...

Paul /)/+)
2008/10/1 Jason Bailey <j.bailey at sussex.ac.uk>

> Hello,
>
> I'm trying to layout some data in a table (sorry any nice examples for a
> nice CSS table type layout). I'm using jquery to allow url to go off and
> bring back some data related to that row and place it next to the row. I'm
> assuming I need to build ids which include the row number so I can see
> which row has been clicked and where to display result (next to row).
>
> I'm trying to get the id of a span tag in a table
>
> e.g. I've got...
> .....<td><a href="">I'm somewhere in here!</a></td><td><span
> id="myid1">test text</span></td>...
>
> If I do:
>  alert("xx"+$(this).parent().next().html()+"xx")  // xx to see if any
> spaces around it
>
> I get: xx<span id="myid1">test text</span>xx
> and
> alert("xx"+$(this).parent().next().text()+"xx")  //gives xxtest textxx
>
> So how do I dip into the above span tag and get the id attribute.
>
> I was thinking something like
>  alert($(this).parent().next().child().attr('id'))
> would do it
>
> Now thinking first child but am still emailing as I'm going a bit loopy
> with this traversing. Any tips on doing this better.
> i.e. I'm creating id tags along the lines of id="id"+rownum and building a
> set of ids with a text and row number part so I can
> 1. See which row (many rows) has been selected
> 2. Display something new in the row.
>
> Bit stuck
> Thanks
> Jason
>
> --
>
> BNM Subscribe/Unsubscribe:
> http://www.brightonnewmedia.org/options/bnmlist
>
> BNM powered by Wessex Networks:
> http://www.wessexnetworks.com
>


More information about the BNMlist mailing list. Powered by Wessex Networks