2015-10-22 60 views
0

遇到問題,我的'p'元素值被附加到'reviewer-meta'塊。我認爲問題可能是在我的追加函數中,'p'元素被添加到所有review-comment-wrap元素。如何僅將附加到具有值B的元素被刪除的塊?附加到數組的單個元素

<div class="reviewer-meta"> 
    <div class="author-attribute">Value A</div> 
    <div class="author-attribute">Value B</div> 
    <div class="review-comment-wrap">some value</div> 
</div> 

<div class="reviewer-meta"> 
    <div class="author-attribute">Value A</div> 
    <div class="review-comment-wrap">some value</div> 
</div> 


function runProgram(){ 
    var theElements = $('.reviewer-meta').find('.author-attribute'); 

    $(theElements).each(function(){ 
     if(this.innerHTML == "Value B"){ 
      $(this).remove(); 
     } 
    }); 
    $('.review-comment-wrap').append('<p>New value</p>'); 
} 
runProgram(); 
+1

:你寫=而不是==。 –

回答

3

常見的語法錯別字。因爲你使用的讓渡,而不是平等的比較,例如,'='與``==

if(this.innerHTML == "Value B"){