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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:14:14+00:00 2026-06-02T06:14:14+00:00

$(function() { $(.commentbox .btnReply).click(function() { $(this).hide(); var id = $(this).attr(id).split(-)[1] var strDiv = <input

  • 0
$(function() {
    $(".commentbox .btnReply").click(function() {
        $(this).hide();
        var id = $(this).attr("id").split("-")[1]
        var strDiv = "<input type='text' class='txtCmnt' id='txtReply-" + id + "' /> <input type='button' class='btnSave' value='Save' id='btnSave-" + id + "' /> ";
        $("#container-" + id).html(strDiv);
    });
    var i = 1;
    $(".commentbox").on("click", ".btnSave", function() {
        var itemId = $(this).attr("id").split("-")[1]
        var txt = $(this).parent().find(".txtCmnt").val();
        var divid = itemId + "-" + i;

 i++;
            alert("i" + i);
        alert("replypostid" + divid);

        $.post("Handler/Topic.ashx", {
            reply: txt,
            id: itemId
        }, function(data) {
            alert(data);
            var str = "<div id='replytopost" + divid + "'></div>";
            $("#replytopost" + divid).append(data);

            $("#container-" + itemId).append(str);


        })

    });
});  

I want to append data returned from post function to a dynamically created div which is appended to another div.

The jsfiddle link is
http://jsfiddle.net/UGMkq/49/

alert(data) is printing correct output but div with data is not getting appended .

Edited

If I click first save button it is giving replypostid1-1 and then
when I click second button alert is giving replypostid2-2 instead I want replypostid2-1

http://jsfiddle.net/UGMkq/50/

  • 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-02T06:14:21+00:00Added an answer on June 2, 2026 at 6:14 am

    you are creating a string, then trying to append to it as if it existed in the DOM. Instead, try this:

    $("#container-" + itemId).append(
       $('<div/>')
          .attr('id', '#replytopost'+divid)
          .append( data )
    );
    

    edit

    I don’t think relying on keeping a counter in Javascript to handle the reply count is a good solution. If the page is refreshed, that counter is lost/reset.

    If this app is database driven, you should be able to get a count of current replies from the database and have better data consistency – have that passed back with the ajax call – maybe as a json object. This will allow you to avoid keeping and incrementing that counter in JS.

    $.post("Handler/Topic.ashx", { reply: txt, id: itemId }, function(data) {
       //Assuming a json object like { "id": 1, "text": "What ever data equals now" }
       var reply = JSON.parse( data );
       $("#container-" + itemId).append(
          $('<div/>')
             .attr('id', '#replytopost'+itemId+'_'+reply.id)
             .append( reply.text )
       );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JSFiddle $(.commentbox).on(click,.btnSave,function(){ var id = $(this).attr(id).split(-); alert(id); id.shift(); alert(id); var newString = id.join('-'); alert(newString);
My js script jQuery(.unblock).click(function(){ var num = jQuery('.page.active').text(); var ban_id = jQuery(this).attr('id'); jQuery.get(http://127.0.0.1/auth_system_1/user_activity/delete_user_ban, {
I have JS : jQuery('.unblock').click(function(){ var num = jQuery('.page.active').text(); var ban_id = jQuery('.unblock').attr('id'); jQuery.post('http://127.0.0.1/auth_system_1/user_activity/delete_user_ban',
<table border=0 class=commentbox> <tr> <td> <div id=comment-f78d0b00-a008-473d-b647-a4a103ee3778></div> <input type=button class='btnReply' id=reply-f78d0b00-a008-473d-b647-a4a103ee3778 value=Reply/> </td> </tr>
This is partial markup: <tr class=Comment> <td class=CommentCheck> <input id=ctl00_col2_rptComments_ctl01_chkBox type=checkbox name=ctl00$col2$rptComments$ctl01$chkBox /> <input
i have this click function note when clicked it should change a couple of
$('.comment_reply').live('focus', function() { var textArea = $(this).find('.comment_content'); }).live('blur', function(e) { var textArea = $(this).find('.comment_content');
html code <table border=0 class=commentbox> <tr> <td>Some Item text </td> </tr> <tr> <td> <div
function icPageInit() { $(icImgDiv + icAlternate()).setOpacity(0); return true; } window.onload = icPageInit; This piece
function text_window() { var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open(GET,cd_catalog.xml,false); xmlDoc.send(); xmlDoc=xmlDoc.responseXML; }

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.