编程语言
首页 > 编程语言> > javascript-jQuery remove()不删除

javascript-jQuery remove()不删除

作者:互联网

我有以下代码使我可以实现shareThis功能.我想做的是单击共享的关闭按钮时,我试图删除共享.share-span附带的功能然后重新初始化它,但是remove()似乎没有删除.span-share from DOM.

<script type="text/javascript">
function getShareData() {
    jQuery(".suit-gallery-btn").each(function(index){
        jQuery(this).children().remove('span');
        jQuery(this).append("<span class='share-span'></span>"); // ShareThis button will be inserted in this span, which we are appending to each <div class="suit-gallery-btn">
        var suitLink = jQuery(this).find('a'); // the "click more information" link. you will need the href and title from this element.
        console.log(suitLink);
        stWidget.addEntry({
            "service":"email",
            "element": jQuery(this).find('.share-span')[0],
            "title":suitLink.attr('title'),
            "type":"large",
            "text":suitLink.attr('title'),
            "image": suitLink.attr('href'),
            "summary":suitLink.attr('title'),
            "onhover": false
        });
    });
}

jQuery(document).ready(function() {
    getShareData();
    jQuery("#closeX, #greyScreen, .stCloseNew2, .close, .close2").live("click", function(){
        getShareData();
    });
});
    <div id="suit-gallery">
  <img src="../images/galleries/business/DSC_0055_sm.jpg" alt="Stylish button 3 business suit, beige lightweight high twist cool wool Holland &amp; Sherry" width="164" height="247" />
  <div class="suit-gallery-btn">
    <a href="../images/galleries/business/DSC_0055.jpg" rel="lightbox[business]" title="Stylish button 3 suit, beige lightweight high twist cool wool Holland &amp; Sherry from £695 choice of 90 designs and colours">Click for more information</a>
</div>
</div>

解决方法:

更改此行:

jQuery(this).children().remove('span');

至:

jQuery(this).children('span.share-span').remove();

可以在此处查看此操作:http://jsfiddle.net/MarkSchultheiss/CUrXF/,我对其进行了些微更改以显示原始范围,然后在调用函数时将其删除.

标签:dom-manipulation,sharethis,javascript,jquery
来源: https://codeday.me/bug/20191102/1990199.html