<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>
Tôi có mã HTML ở trên và tôi muốn nhận giá trị của thuộc tính rel
khi tôi nhấp vào hình ảnh. Tôi đã viết kịch bản jQuery này, nhưng nó dường như không làm việc:Làm thế nào để có được attr với jQuery?
$('div.item').click(function() {
var getvalue = $('this > p > img').attr('rel');
alert(getvalue);
});