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 5952129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:38:14+00:00 2026-05-22T17:38:14+00:00

I got a list that i wan’t to interrupt via javascript to add a

  • 0

I got a list that i wan’t to interrupt via javascript to add a title:

From:

<ul>
    <li>1</li>
    <li class="afterthis">2</li>
    <li>3</li>
    <li>4</li>
</ul>

To:

<ul>
    <li>1</li>
    <li class="afterthis">2</li>
</ul>
<h1>Title</h1>
<ul>
    <li>3</li>    
    <li>4</li>    
</ul>

i thought that was easy by doing: $(".afterthis").after("</ul><h1>Title</h1><ul>");

but it doesn’t close the list, it moves the end tag, it inserts <h1>Title</h1><ul></ul>

to see the problem see this jsfiddle http://jsfiddle.net/Fx74b/14/

  • 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-22T17:38:15+00:00Added an answer on May 22, 2026 at 5:38 pm

    Jquery works with valid HTML only, not string parts.

    So you cannot pass broken html to the after() method.

    You will need to split the ul your self and add the other elements in between.

    $(document).ready(function() {
        var splitelement = $(".afterthis"); // find the element which will be used for the split
        var ul = splitelement.parent(); // find the relative ul
        var newul = $('<ul>'); // create the new ul that will follow the existing one
    
        newul.append( splitelement.nextAll() ); // move the rest of the li elements to the new ul
        ul.after("<h1>Title</h1>").next().after(newul); // insert the title and then then ul
    });
    

    demo http://jsfiddle.net/gaby/ph5UM/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a dropdown list that is being populated via a webservice using ASP>NET
I've got a list of People that are returned from an external app and
I've got a collection (List<Rectangle>) which I need to sort left-right. That part's easy.
I have got list that is filled with data from internet. Datas are downloaded
I got a List that I add to every time I create a new
I've got a list that is generated from some server side code, before adding
In my c# app, I've got a list that I navigate with an Enumerator.
In Python, I've got a list of dictionaries that looks like this: matchings =
In my Flex interface, I've got a few List components that are data bound
I've got a list in a Python program that contains a series of numbers,

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.