Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:23:32+00:00 2026-06-18T07:23:32+00:00

html structure: <div class=row> <div class=span></div> <div class=span></div> <div class=navMenu> <ul> <li><a href=#>Link 1</a></li>

  • 0

html structure:

<div class="row">
   <div class="span"></div>
   <div class="span"></div>
   <div class="navMenu">
       <ul>
           <li><a href=#">Link 1</a></li>
           <li><a href=#">Link 1</a></li>
       </ul>
    </div>
</div>

Then I am adding a “new” div just after the above html:

   <div class="row">
      <div class="span"></div>
      <div class="span"></div>
      <div class="navMenu">
        <ul>
           <li><a href=#">Link 1</a></li>
           <li><a href=#">Link 1</a></li>
        </ul>
      </div>
   </div>
   <div class="new"></div>

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

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

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

It is IMPORTANT that the new div with class .new 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 .row divs, so I wanted to target the correct one.

The above final code doesn’t work tho

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:23:33+00:00Added an answer on June 18, 2026 at 7:23 am

    You don’t need the each loop – also you notice how .new and .row are siblings?

    $(".navMore li a").on("click", function() {
      var $el = $(this);
      var $row = $el.closest('.row'); // <-- get to row first
      if($row.next('.new').length){ // check next element
          $('<div class="span"></div>').appendTo('.new');
      }
      else {
            $('<div class="new"></div>').insertAfter($row);
            $('<div class="span"></div>').appendTo('.new');
      }
    });
    

    You also have your classes mixed up.. So you need to make sure they match

    <div class="navMenu"> <!-- <-- here -->
        <ul>
           <li><a href="#">Link 1</a></li>
           <li><a href="#">Link 1</a></li>
        </ul>
      </div>
    

    and

    $(".navMore li a") // <-- here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two jQuery questions: 1) Given this HTML structure <div id=tipper class=tiplink><a href='test.html' >Link Text</a>
I have the following html page structure: <div class=result-row clearfix> <span>Name1</span> <span>city1</span> <span>phone1</span> <span>details1</span>
I have this HTML structure: <div class=article-body> <p> <a href=http://www.example.com>My Link</a> Lorem Ipsum Dolor
I have this html structure <div class=top_menu> <ul> <li class=left><a href= class=family-filter>asdas</a></li> <li class=welcome>Welcome
I have the following HTML structure,which is a handlebars.js template.: <div class=row id={{serviceId}}> <div
I have the following HTML structure: <div class=s1> <div class=s2> <span class=span1> <span>text</span> </span>
I have the following HTML structure: <div id=settings-choose> <a href=#setting1 class=setting-tab> <div class=content> <div
Consider the following HTML structure for drop-down menu: <ul class=tabMenu> <li><a href=#>Games</a> <div id=sub>
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a
//html structure <div id='outer'> <div id='inner'> </div> </div> I am adding some data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.