附加到数组的单个元素

时间:2015-10-22 14:52:18

标签: javascript loops append

我的'p'元素值被附加到'reviewer-meta'块时出现问题。我认为问题可能是在我的附加功能中,' p' element被附加到所有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 个答案:

答案 0 :(得分:3)

常见的语法拼写错误。您写了=而不是==

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