2017-05-07 50 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 
    }); 
}); 
相關問題