tags:

views:

34

answers:

3

hello,

if I have the following table:

<tr class="alternate">
    <td>{$order.titel}</td>
    <td>{$order.auteur}</td>
    <td>&euro;{$order.prijs}</td>
    <td>{$order.aantal}</td>
    <td>&euro; {$order.aantal*$order.prijs}</td>
<tr>

and inside jquery I currently have the 4th td selected, how can i get the data from within the first td, keeping in mind that I start looking from the 4th td (eg. the 4th td is 'this')?

+1  A: 

You can use the prev() method which returns the preceding sibling.

var first = $(this).prev().prev().prev();
Saul
A: 

You can call the prevUntil() method to match the first <td> element:

var first = $(this).prevUntil("td:eq(0)");
Frédéric Hamidi
+2  A: 
var first = $(this).siblings().first();

Or, for one of the other elements:

var second = $(this).siblings().eq(1);
lonesomeday
Shouldn't that be `:eq(0)`?
Frédéric Hamidi
@Frédéric Hamidi: No, eq is 1-based
Harmen
@Harmen, [really](http://api.jquery.com/eq-selector/)? Documentation says it's zero-based.
Frédéric Hamidi
Yes, it's zero-based. Hence `second = ` :-)
lonesomeday
@Frédéric Hamidi: You're right, I'm confused with `nth-child()` which is 1-based
Harmen
@lonesomeday, you're right, I was blinded by the question mentioning the first `<td>` :)
Frédéric Hamidi