jQuery改变了多个div元素的内联样式

时间:2013-09-13 12:29:03

标签: javascript jquery

我有一些html代码,想要改变

内联样式

  

显示:块

  

显示:无

哪个班级 ln-b ln-z

<div class="filter-div ln-b" style="display: block;"></div>
<div class="filter-div ln-c" style="display: block;"></div>
<div class="filter-div ln-d" style="display: block;"></div>
<div class="filter-div ln-e" style="display: block;"></div>
<div class="filter-div ln-f" style="display: block;"></div>
<div class="filter-div ln-g" style="display: block;"></div>
<div class="filter-div ln-h" style="display: block;"></div>
<div class="filter-div ln-i" style="display: block;"></div>
<div class="filter-div ln-j" style="display: block;"></div>
<div class="filter-div ln-k" style="display: block;"></div>
<div class="filter-div ln-l" style="display: block;"></div>
<div class="filter-div ln-m" style="display: block;"></div>
<div class="filter-div ln-n" style="display: block;"></div>
<div class="filter-div ln-o" style="display: block;"></div>
<div class="filter-div ln-p" style="display: block;"></div>
<div class="filter-div ln-q" style="display: block;"></div>
<div class="filter-div ln-r" style="display: block;"></div>
<div class="filter-div ln-s" style="display: block;"></div>
<div class="filter-div ln-t" style="display: block;"></div>
<div class="filter-div ln-u" style="display: block;"></div>
<div class="filter-div ln-v" style="display: block;"></div>
<div class="filter-div ln-w" style="display: block;"></div>
<div class="filter-div ln-x" style="display: block;"></div>
<div class="filter-div ln-y" style="display: block;"></div>
<div class="filter-div ln-z" style="display: block;"></div>

有任何想法或建议吗?感谢。

5 个答案:

答案 0 :(得分:3)

我建议(假设它们按顺序出现并且是兄弟姐妹),有一个.filter-div.ln-a元素你不想隐藏:

$('.filter-div.ln-b').nextUntil($('.ln-z').next()).addBack().css('display','none');

JS Fiddle demo

参考文献:

答案 1 :(得分:0)

$('div[class*="ln-"]').hide();

答案 2 :(得分:0)

$(".filter-div").css("display","none"); 

$('.filter-div').each(function() {
   $(this).css("display","none"); 
}

答案 3 :(得分:0)

您可以使用:attr

$(".filter-div").attr('style', 'display:none');

DEMO

答案 4 :(得分:0)

试试这个:

$('div[class*="ln-"]').css('display','none');