 <p>Try <a href="https://api.jquery.com/nextUntil/" rel="nofollow"><code>.nextUntil()</code></a>:</p> <pre><code>$(".lev1").click(function(){ $(this).nextUntil(".lev1").toggle(); }); </code></pre> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".lev1").click(function(){ $(this).nextUntil(".lev1").toggle(); });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class='folder lev1'&gt;323&lt;/div&gt; &lt;div class='folder lev2'&gt;525&lt;/div&gt; &lt;div class='file lev3'&gt;727&lt;/div&gt; &lt;div class='file lev4'&gt;1625&lt;/div&gt; &lt;div class='folder lev1'&gt;new&lt;/div&gt;</code></pre> </div> </div> </p>