Hide all DOM children until <hr / "> is found
I wonder how to hide all elements until the first <hr/> . Then the loop should stop
<div class='row-father'> <legend> Title here </legend> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <hr/> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <hr/> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <hr/> </div> ...
$('.row-father').find('*').each(function(){ if ($(this) != '<hr/>') $(this).hide(); }); +4
4 answers
Use this: $('.row-father > hr:first').prevAll(':not(legend)').hide(); See http://api.jquery.com/prevall/
+9
you can also use
$('.row-fluid:first').nextUntil("hr").andSelf().hide();
Edit:
if you want to replace <hr/> with a div containing text, for example:
<div class='row-father'> <legend> Title here </legend> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <div>test</div> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <hr/> <div class="row-fluid">...</div> <div class="row-fluid">...</div> <hr/> </div> you can try this code:
$('.row-fluid:first').nextUntil("div>:contains('test')").andSelf().hide(); 0