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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:32:19+00:00 2026-06-15T21:32:19+00:00

I am trying to append a list element dynamically to already existing list. I’ve

  • 0

I am trying to append a list element dynamically to already existing list.

I’ve a list in the form,

<ul id="test">
    <li class="testField">YYAAHOOOOOO<li>
</ul>

I am trying to add an extra item to this list using jQuery append or after…

What I did was:

$(".testField").after("<li class='testField'>TEST MESSENGER</li>"); 

Used after function as append did not work, the after function works fine first time as there is only one element with the class name testField, but as the list grows, the after function will add the list items to all elements present,

To make it clear, on first trial I will get an output:

<ul id="test">
    <li class="testField">YYAAHOOOOOO<li>
    <li class='testField'>TEST MESSENGER</li>
</ul>

If I try the to add another element now for example <li class='testField'>GOOGLE</li>, the output will be like:

<ul id="test">
    <li class="testField">YYAAHOOOOOO<li>
    <li class='testField'>GOOGLE</li>
    <li class='testField'>TEST MESSENGER</li>
    <li class='testField'>GOOGLE</li>
</ul>

I thought about using ids, but I am trying to have an option to remove elements from the list too… So if I try to append to an undefined id, it will return error. Is there anyway to find the first element inside a list and append the element to that first one?

  • 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-15T21:32:20+00:00Added an answer on June 15, 2026 at 9:32 pm

    Try:

    $(".testField:first").after("<li class='testField'>TEST MESSENGER</li>"); 
    

    this will make sure that you are appending after the first element only

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

Sidebar

Related Questions

I am trying to append a li element to a list with a link
I am trying to dynamically add some content to a list of checkboxes in
Hi I am trying append a simple element to a lisp list. (append queue1
I'm trying to append a new float element to a list within another list,
I am trying to add some extra data using jQuerys .data() to a element
I'm trying to add element from a Jlist to another , append if this
B=l.append((l[i]+A+B)) l is a list here and i am trying to append into it
I'm trying to append a CSS class to a row on RowDataBound. I'm using
I'm trying to create a list of objects (Elements), where each element contains a
I'm trying to find the index of specifyed element in my list that looks

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.