微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jQuery用img包装img

你好,如果类有锚,我试图用锚包装图像.

jQuery的:

if ( $(".views-row:has(a)").length) {
    var noderef = $(this).attr("anchor");
    $(".views-field-field-teaserBox-fid img").wrap("[anchor = "'+noderef+'" ]");
}

HTML:

<div class="view-content">
        <div class="views-row">

          <div class="views-field-field-node-ref-nid">
           <span class="field-content"><a class="active" href="/all-essentials-inspiring-events">All the essentials of inspiring events.</a></span>
         </div>

         <div class="views-field-field-teaserBox-fid">
            <span class="field-content"><img width="208" height="137" src="http://localhost:8888/sites/default/files/wedding_Giveaway_teaser.jpg?1283880578" alt="" class="imagefield imagefield-field_teaserBox"></span>
    </div>

另外,我应该使用双引号还是单引号?

解决方法

这个怎么样?
$("img.anchor").wrap('<a href="#" />');

ref:http://api.jquery.com/wrap/

原文地址:https://www.jb51.cc/jquery/177241.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐