Not actually ran this but have you tried something like this:
<script>
jQuery.ready(function(){
$('.spantoclick').click(function(){
var target = $('myid_' + this.id.split('_')[1]);
});
})
</script>
</head>
<body>
<table>
<tr>
<td>
<a href="" id="spantoclick_1" class="spantoclick">I'm
somewhere in here!</a>
</td>
<td>
<span id="myid_1">test text</span>
</td>
</tr>
</table>
</body>
</html>
Obviously some nasty string splitting to get Ids etc but it'd work. I
haven't worked with JQ for a while but I think that the 'this' in this
context should work :s
Someone may need to correct me there :)
Hth
W://
-----Original Message-----
From: bnmlist-bounces at brightonnewmedia.org
[mailto:bnmlist-bounces at brightonnewmedia.org] On Behalf Of Jason Bailey
Sent: 01 October 2008 11:40
To: brighton new media
Subject: [BNM] jquery traversing help!
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