当前位置: 动力学知识库 > 问答 > 编程问答 >

Hide next div which matches the the condition using jquery

问题描述:

I'm able to wrap the text inside a div and hide them. In addition to that I need to hide the next div also. But, it doesn't work. Did I miss anything?

Here is my html

<small>

Size: M<div class="item-devider"></div>

checkbox_test: Yes<div class="item-devider"></div>

I don't mind about color: No<div class="item-devider"></div>

test: No<div class="item-devider"></div>

test_group: select1<div class="item-devider"></div>

</small>

JQuery

$(document).ready(function(){

var texts = $('#sample small').contents().filter(function(){

return $(this).text().indexOf(': No') > -1;

}).wrap('<div style="display:none"/>').next().find('div').attr('display:none');

});

Fiddle http://jsfiddle.net/EwNRJ/1136/

Any ideas would be greatly appreciated

网友答案:

You need to hide the next sibling of parent div that you wrap around your text instead:

$(document).ready(function(){   
    var texts = $('#sample small').contents().filter(function(){
        return $(this).text().indexOf(': No') > -1;     
    }).wrap('<div style="display:none"/>').parent().next().hide();
});

Updated Fiddle

分享给朋友:
您可能感兴趣的文章:
随机阅读: