Skip to content Skip to sidebar Skip to footer

Jquery Undo Append

I've got a table with a button inside a td, once I press the button it adds text to the td. I want to remove this text inside the td once i press the button again. note that this b

Solution 1:

You could create ID for text inside like this:

$(document).on('click', '.releasebutton', function () { // button class="releasebutton"var label = $(this).text();
    if (label == "Add") { // it is "Add" by default
        $(this).text("Cancel");
        $('.ReleaseTD').append("<span id='textID'><br>" + "test</span>");
    }
    else {
        $(this).text("Add");
        $('#textID').remove(); 
    };
});

Solution 2:

Please try the following:

$(document).on('click', '.releasebutton', function () { // button class="releasebutton"var label = $(this).text();
    if (label == "Add") { // it is "Add" by default
        $(this).text("Cancel");
        $('.ReleaseTD').append("<span id='txt_name'><br>" + "test</span>");
    }
    // the code above this workselse {
        $(this).text("Add");
        $('#txt_name').remove(); 
    };
});

Post a Comment for "Jquery Undo Append"