Check if next element has a specific class
<p>html structure:</p>

<pre><code>&lt;div class="row"&gt;
   &lt;div class="span"&gt;&lt;/div&gt;
   &lt;div class="span"&gt;&lt;/div&gt;
   &lt;div class="navMenu"&gt;
       &lt;ul&gt;
           &lt;li&gt;&lt;a href=#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href=#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Then I am adding a "new" div just after the above html:</p>

<pre><code>   &lt;div class="row"&gt;
      &lt;div class="span"&gt;&lt;/div&gt;
      &lt;div class="span"&gt;&lt;/div&gt;
      &lt;div class="navMenu"&gt;
        &lt;ul&gt;
           &lt;li&gt;&lt;a href=#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href=#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
   &lt;/div&gt;
   &lt;div class="new"&gt;&lt;/div&gt;

$(".navMore li a").each(function() {
   $(this).on("click", function() {
            $('&lt;div class="new"&gt;&lt;/div&gt;').insertAfter($(this).closest('.row'));
            $('&lt;div class="span"&gt;&lt;/div&gt;').appendTo('.new');
   });
});
</code></pre>

<p>Finally I need to check if a div with class <code>.new</code> exists RIGHT AFTER the div containing the menu, and if so add a <code>.span</code> div in it, and if a div with class <code>.new</code> doesn't exist, then create it and then insert a div with class <code>.span</code> in it:</p>

<pre><code>$(".navMore li a").each(function() {
   $(this).on("click", function() {
      if($(this).next().hasClass("new")){
          $('&lt;div class="span"&gt;&lt;/div&gt;').appendTo('.new');
      }
      else {
            $('&lt;div class="new"&gt;&lt;/div&gt;').insertAfter($(this).closest('.row'));
            $('&lt;div class="span"&gt;&lt;/div&gt;').appendTo('.new');
      }
   });
});
</code></pre>

<p>It is IMPORTANT that the new div with class <code>.new</code> is a div with such a class right next the div container the menu. The reason why is because I will many menus with many different <code>.row</code> divs, so I wanted to target the correct one. </p>

<p>The above final code doesn't work tho</p>
