<div class="item">
<p><img src="images/photos_sample1.jpg"
border="0" rel="images/google_map.jpg"></p>
<p>Dining Area</p>
</div>
<div class="item">
<p><img src="images/photos_sample2.jpg"
border="0" rel="images/sample_photo.jpg"></p>
<p>Pool Area</p>
</div>
我有上面的HTML代碼,我想單擊圖像時獲取rel
屬性的值。我寫這個jQuery腳本,但它似乎並沒有工作:如何使用jQuery獲取attr?
$('div.item').click(function() {
var getvalue = $('this > p > img').attr('rel');
alert(getvalue);
});