當用戶點擊class click_1時,我想要顯示圖像的路徑。請注意,click_1發生在兩種情況下。jquery選擇器獲取圖像路徑
<a href="#" class='click_1' ><img src="assets/img/shoe05.png" /></a>
<h4><a href="#" class='click_1' >title link 2</a></h4></li>
$('.click_1').click(function() {
var fullPath = $(this).children("img:first").attr('src');
if (typeof fullPath === "undefined"){
// this one does not work...
var fullPath = $(this).prev("img").children("img:first").attr('src');
console.log(fullPath);
}
}
所有很好的答案。這是最簡單的。 –