2011-09-01 52 views
3

我會在前言中說我是一個總共jquery新手。不過,我想使用jQuery插入帶有進下面的代碼位的<a>標籤「太極拳」的值的「相對」屬性...使用jquery在<a>標籤中插入'rel'屬性標籤

<div class="bibImage" title=""> 
<a href="" target="_parent"><img src="" border="0" alt=""></a> 
</div> 

這是系統生成的HTML ,所以我沒有添加'class'或'id'屬性的選項,這有助於jquery定位元素。 div是唯一標識的,所以我猜測可以將<a>指定爲孩子(?);但我真的不知道如何。我也不明白哪種方法可以用來實際插入'rel'屬性+值。

在此先感謝您的任何見解和指導。

回答

4
$(function() { // this signifies when the DOM is ready 
    $('.bibImage a').attr('rel', 'shadowbox'); // this will add it to 
               // all <a> inside the <div> 
}); 
+0

輝煌 - 這並獲得成功;正是我需要的。非常感謝! – Doug

1

試試這個

$('.bibImage a').attr('rel', 'shadowbox'); 
1
$('.bibImage a:first-child').attr('rel', 'shadowbox');