tags:

views:

44

answers:

3
<div class="severalDivs">
    <table>
        <tbody>
            <tr>
                <td class="target">
                    <a href="link"></a>
                </td>
            <tr>
        </tbody>
    </table>
    <div class="fromHere">
        <a href="somescript()"></a>
    </div>
</div>

How do I with Jquery get "link" in "target" when clicking the anchor with "somescript()" in "fromHere"?

Hope It's clear what I want to do. =)

+1  A: 

try:

$('.fromHere a').click(function(){
   var link = $('.target a').attr('href');
   alert(link);
   return false;
})
Reigel
+1  A: 
function somescript( ) {
    var href = $("td.target a").attr("href");
}
Salman A
+2  A: 

You mean like this?

$('div.fromHere').find('a').click( function(e) {
    var div = $(this).closest('div.severalDivs');
    var targetLink = div.find('td.target a');
    e.preventDefault();
});

This allows you to have several divs like the one you gave as an example, and always find the correct link.

Tom Bartel
Thanks Tom, exactly what I needed.
Jova
You're welcome, glad to hear that.
Tom Bartel