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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:33:06+00:00 2026-05-24T22:33:06+00:00

My application adds new posts to an <ul> using .prepend() and then uses the

  • 0

My application adds new posts to an <ul> using .prepend() and then uses the .ajax() function to add it to the database like so:

$("#add input[type=submit]").click(function(){
    newPost = $("#add textarea").val();
    $.ajax({
        type    : "POST", 
        url     : "/add", 
        data    : { "post" : newPost },
        success: function(data) {               

           $('#posts ul').prepend('<li id="1234"><p>'+newPost+'<p><span class="delete">Delete</span></li>');
        }
});

This works as intended, but as you can see I have a Delete button for each post and I delete post using the following jquery:

$(".delete").click(function(){
    var thiscache = $(this),
    post_id = thiscache.closest("li").find("p").attr("id");

    $.ajax({
        type    : "POST", 
        url     : "/delete", 
        data    : { "post_id" : post_id },

        success : function(r){ 
            thiscache.parent().slideUp('slow'); 
            },

    });
});

Delete will work with post that have been added previously, but if you add a post using the ajax form, and click delete nothing fires. What could be the cause of this? Maybe the new post <li> isn’t in the DOM?

I created a JSfiddle without the Ajax functions. http://jsfiddle.net/bhhgf
If you add a new post it will append it, but you can not delete it. Deleting the current posting works just fine.

EDIT:

I also use jeditable with a custom event, but .live() will not tigger new post.

$("p").editable('/edit/save', {event : 'edit_button'});

$(".edit").live('click', function(){       
    $(this).closest("li").find("p").trigger('edit_button');
});
  • 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-24T22:33:07+00:00Added an answer on May 24, 2026 at 10:33 pm

    for the dynamically added elements to the DOM you need to rebind the event handler to them or use .live or .delegate

    $(".delete").live('click',function(){
    
    });
    

    or

    $("#posts ul").delegate(".delete","click",function(){
    
    });
    

    jquery live

    jquery delegate

    for the edit link in your first ajax callback again call the jeditable on the desired elements

        $("#add input[type=submit]").click(function(){
            newPost = $("#add textarea").val();
            $.ajax({
                type    : "POST", 
                url     : "/add", 
                data    : { "post" : newPost },
                success: function(data) {               
    
                   $('#posts ul').prepend('<li id="1234"><p>'+newPost+'<p><span class="delete">Delete</span></li>');
                 //call editable here on the desired elements
                 $("p").editable('/edit/save', {event : 'edit_button'});
                }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone application that adds new contacts via the Address Book Framework.
I have a web application that adds contextual information to XmlHttpRequest objects using the
I'm creating a simple drawing application that adds new Shape objects to a MovieClip
I'm developing an application where the user adds new rows to an existing table.
Our application adds objects to the cache using the following int cacheTimeout = 5;
Working on a Wicket application that adds markup to the DOM after onLoad via
I have an application written in Delphi that adds / updates contacts in outlook.
An application I use, Mozy Backup , adds its own drive to Windows Explorer
Application 1 - Opens a SqlConnection and a SqlTransaction against a SQLServer 2005 database
Application is asp.net MVC. I want to put a textbox for date using mask.

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.