2011-08-24 10 views
2

shareThis 기능을 구현할 수있는 다음 코드가 있습니다. 내가 뭘 하려는지이 오버레이 공유의 닫기 버튼을 클릭했을 때 .share-span과 함께 제공되는 shareThis 기능을 제거한 다음 다시 초기화하지만 remove()은 DOM에서 .span-share을 제거하지 않는 것 같습니다.jquery remove() 제거하지 않음

<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> 
+0

dom의 예를 들어 주시겠습니까? –

답변

1

변경이 라인 :

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

에 :

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

여기에 행동이보기 : 나는 약간 변경 http://jsfiddle.net/MarkSchultheiss/CUrXF/ 다음의 제거를 원래의 범위를 표시하기 위해 함수가 호출 될 때 .

2

당신은 제거의 의미를 오해했습니다.

제거해야하는 객체에서 제거를 호출합니다. 제거하려는 객체에서 제거하지 말고 제거해야합니다. 같은

뭔가 :

내가 무엇을 볼 수에서
jQuery('span.share-span', jQuery(this)).remove(); 
+0

제거 코드가 정확합니다. 그것의 바로 그 다음 라인에 다시 추가됩니다 .http : //jsfiddle.net/naveen/UxBht/ 더하기, 당신은 누락되었습니다.. – naveen

1

, 원래의 코드에는 span이 없습니다.

appended가되기 전에 remove()span에 표시되는 것처럼 보입니까?

+0

+1 : 당신은 대답에서 첫 번째 라인을 제거 할 수 있습니다 – naveen

+0

고마워요 @naveen . 내가 의미하는 바는 HTML에서'span'을 보지 못했다는 것입니다. –

+0

충분히 공정합니다 :) – naveen