use jquery to insert 'rel' attribute in <a> tag
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开发者_JAVA百科 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>
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>
});
Try this
$('.bibImage a').attr('rel', 'shadowbox');
$('.bibImage a:first-child').attr('rel', 'shadowbox');
精彩评论