使用jquery在< a>中插入'rel'属性标签 [英] use jquery to insert 'rel' attribute in <a> tag
问题描述
我会先说这是一个全新的jquery新手。也就是说,我想使用jquery将值为shadowbox的'rel'属性插入到以下代码中的< a>
标记中...
I'll preface this by saying that I'm a total jquery newbie. That said, I'd like to use jquery to insert a 'rel' attribute with a value of "shadowbox" into the <a>
tag in the following bit of code...
<div class="bibImage" title="">
<a href="" target="_parent"><img src="" border="0" alt=""></a>
</div>
这是系统生成的html,所以我没有选择添加'class'或'id'属性可以帮助jquery定位元素。 div是唯一标识的,所以我猜测可以将< a>
指定为子(?);但我真的不确定如何。我也不明白哪种方法可用于实际插入'rel'属性+值。
This is system-generated html, so I don't have the option of adding 'class' or 'id' attributes which would help jquery target the element. The div is uniquely identified, so I'm guessing that it's possible to specify the <a>
as a child(?); but I'm really not sure how. Nor do I understand which method can be used to actually insert the 'rel' attribute + value.
提前感谢任何见解和指导。
Thanks in advance for any insight and guidance.
推荐答案
$(function() { // this signifies when the DOM is ready
$('.bibImage a').attr('rel', 'shadowbox'); // this will add it to
// all <a> inside the <div>
});
这篇关于使用jquery在< a>中插入'rel'属性标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!