I have the following markup:
<tr> <td> <a>foo</a> </td> <td>bar</td> <td> <a class="delete-btn">delete</a> </td> </tr>
I’ve already hooked up a click event handler using jquery $(".delete-btn")
the problem is that inside the click event handler I need the text of the first element (foo).
I’m already getting the value I need with this call:
$(this).closest("tr").children().first().children().first("a")
but I feel it’s too verbose. Is there a better way to accomplish this?
Advertisement
Answer
I don’t like this either, but… it’s exactly what you’re looking for:
$(this).closest("tr").find("> td:first-child > a");