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

  • SEARCH
  • Home
  • 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 7085079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:22:50+00:00 2026-05-28T07:22:50+00:00

I crossed uppon a weird problem. I have a list with links like so:

  • 0

I crossed uppon a weird problem. I have a list with links like so:

<ul class="sub-navigation">
    <li><a href="">a</a></li>
    <li><a href="">b</a></li>
    <li><a href="">c</a></li>
    <li><a href="">d</a></li>
    <li><a href="">e</a></li>
</ul>

What I want to do is make jQuery split the list in two by inserting closing and then opening tags after, say, the third list item. So I go like so:

$('.sub-navigation li').eq(2).after('google');

It properly inserts the text and I get:

<ul class="sub-navigation">
    <li><a href="">a</a></li>
    <li><a href="">b</a></li>
    <li><a href="">c</a></li>google
    <li><a href="">d</a></li>
    <li><a href="">e</a></li>
</ul>

which is correct, but when I try to insert the actual tags like so:

$('.sub-navigation li').eq(2).after('</ul><ul class="sub-navigation">');

it reverses them o_O

<ul class="sub-navigation">
    <li><a href="">a</a></li>
    <li><a href="">b</a></li>
    <li><a href="">c</a></li><ul class="sub-navigation"></ul>
    <li><a href="">d</a></li>
    <li><a href="">e</a></li>
</ul>

Why is that so? Can’t before() just insert the raw HTML I gave it?
If I try to insert just </ul> it dissapears…

Thanks in advance!

  • 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-05-28T07:22:51+00:00Added an answer on May 28, 2026 at 7:22 am

    jQuery methods such as before() and after() manipulate the browser’s DOM tree.
    The DOM holds complete HTML elements. You can’t put in half of a tag.

    Instead, you need to manipulate entire tags:

    $('.sub-navigation li:eq(2)').nextAll().remove().appendTo(
        $('<ul class="sub-navigation">').insertAfter($('.sub-navigation'))
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I crossed the same problem of Linq provider in this linq-to-nhibernate-produces-unnecessary-joins List<Competitions> dtoCompetitions;
I don't have a specific scenario in mind, but this question just crossed my
I have a <div> with the following css properties set via its class :
I have been struggling with a problem for a couple of days now with
a problem crossed my way more than once. I'm using a Linq DataClass in
Random question that crossed my mind: If I define an array in PHP like
I am trying to have 2 tables with crossed foreign keys, but I am
I've been studying Haskell in my spare time and have recently crossed into the
I have come a crossed the IE > TD > white-space:nowrap; bug and have
I want to find if an int value just has crossed 0. Or if

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.