javascript - JQuery undo append -


i've got table button inside td, once press button adds text td. want remove text inside td once press button again. note this button used multiple times in table hence class attribute. method use done?

this code:

$(document).on('click', '.releasebutton', function () { // button class="releasebutton"     var label = $(this).text();     if (label == "add") { // "add" default         $(this).text("cancel");         $('.releasetd').append("<br>" + "test"); // td class="releasetd"     }     // code above works     else {         $(this).text("add");         $('.releasetd').remove("<br>" + "test");          // wrong correct code     }; }); 

you create id text inside this:

$(document).on('click', '.releasebutton', function () { // button class="releasebutton"     var label = $(this).text();     if (label == "add") { // "add" default         $(this).text("cancel");         $('.releasetd').append("<span id='textid'><br>" + "test</span>");     }     else {         $(this).text("add");         $('#textid').remove();      }; }); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -