2017-05-07 67 views
0

我需要帮助(我相信)非常简单的选择器。这是HTML:jquery - 从第二个标签中选择文本

<a href="http://localhost/index.php?action=profile;u=3" target="_blank"> 
    <img src="http://localhost/index.php?action=dlattach;attach=44;type=avatar" alt="" style="max-width: 16px; max-height: 16px; vertical-align: middle;"> 
</a> 
<a href="http://localhost/index.php?action=profile;u=3" target="_blank" style="color:#8c121a">profilename</a> 

我在做什么是捕捉到的IMG标签点击,然后我想从二号标签的“PROFILENAME”的文字。

感谢您的帮助!

+1

'父()。下一个()。文本()' – mplungjan

+0

就像一个魅力。谢谢。 – saturnusringar

回答

0
$(document).on('click', 'img', function(event) { 
    var text = $(this).parent().next().text(); 
    alert(text); 
}); 
+0

工程就像一个魅力。谢谢。 – saturnusringar

+0

@mplungjan为什么不发布你的答案,所以saturnusringar可以标记为正确的答案,我会删除我的。没有问题 –

0

尝试单纯地喜欢这 -

$(document).ready(function(){ 
    $('img').click(function(){ 
     var text = $(this).parent('a').next('a').html(); 
     // play with text 
    }); 
}); 
相关问题