2011-09-01 98 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');