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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:00:38+00:00 2026-05-28T01:00:38+00:00

I am creating and populating a list with jQuery and want to add an

  • 0

I am creating and populating a list with jQuery and want to add an li element dynamically.

I’ve tried the following but it didnt work for me. Instead the browser crashed. Can anyone help?

$(document).ready(function() {
$(".tophundredwatchlist").hide();

$(".addtophundredwatchlist").click(function() {
        $.ajax({
            type : "GET",
            url : "/watchlisttophundred/",
            success : function(data){
                generateList(data);
            }
        });
        $(this).next().toggle();
        return false;
    });

//this section draws the list

function generateList(data)
{
    var raw_tag = "<ul id='listwatchlist' class='listwatchlist'>";
    var add_new = "Add New"
    var json_array = data.json_array;
    for (var json_count = 0; json_count < json_array.length; json_count++)
    {
        var raw_string = "<li id='watchlistitem' class='watchlistitem'>" + json_array[json_count].watch_list_name + "</li>"
        raw_tag = raw_tag + raw_string
    }
    raw_tag =  raw_tag + "<div id='addnew' class='addnew'>" + add_new + "</div>"
    raw_tag =  raw_tag + "<div id='newtext' class='newtext'></div>"
    raw_tag = raw_tag + "</ul>"
    $(".listwatchlist").html(raw_tag)
}

//when i try to add the new li like this my browser crashes
$('.newwatchlisttext').live("keypress",function(event) {
    if(event.which == '13'){
        var watch_list_name = $(this).val();
        /**********************************************************/
        $.ajax({
            type : "GET",
            url : "/addwatchlistfromtophundredajaxhandler/",
            data : "watch_list_name=" + watch_list_name,
            success : function(msg){
                //$("listwatchlist ul").append('<li>' + data.watch_list_name + '</li>');
            }
        });
        /**********************************************************/
        $(".addnew").show()
        $(".newtext").hide()

        }
});
  • 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-28T01:00:38+00:00Added an answer on May 28, 2026 at 1:00 am

    Your selector is wrong. You should replace this line:

    $("listwatchlist ul").append('<li>' + data.watch_list_name + '</li>');
    

    with:

    $("ul#listwatchlist").append('<li>' + data.watch_list_name + '</li>');
    

    Oh and also the nesting the div in the ul as the other answer points out.

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

Sidebar

Related Questions

I am populating a listbox full of HubTile items dynamically, but the list does
I am dynamically populating a winforms combo box by creating a list from a
I want to make some kind of list of errors in C#, but I'm
Having issues with dynamically creating <select> tags and then populating them with XML values.
I'm dynamically creating the columns and rows of my DGV , and then populating
Im populating a ListView using the following: list = (ListView) findViewById(R.id.historylist); ArrayList<HashMap<String, String>> mylist
I have a gridview I am populating it by creating a datatable filling that
does Android have a best practices guideline on creating & populating the db/tables programmatically
In Ember.js, I'm creating a user object like so, populating it from a JSON
I'm populating a listview with a list of databases on a selected SQL instance,

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.