javascript - How to remove jQuery element added by .append()? -
general info
i'm working on intranet based administration system distribution centre.
situation
basicly have contenteditable table user data. except passwords of course. compare webbased excel sheet. using jquery ui dialog, i'm popping op form allows admin (company manager) of system change employees passwords if clicked on button.
to make sure password change applied correct user, i'm passing along used id function pops dialog. using .append()
i'm adding id form. point works fine.
problem
if password change cancelled, id must removed form again. otherwise end appending more , more ids form on each user clicked. same goes when password change succeeded. i've tried doing jquery .remove()
, doesn't seem work, though can't find issue code.
code
function changepass(id){ var addid = $("<input>") .attr("type", "text") .attr("id", "userid") .attr("name", "userid").val(id); $('#passchangeform').append($(addid)); $("#changepass").dialog({ modal: true, resizable: false, title: "change password", buttons: [ { text: "cancel", click: function() { $("#passchangeform").remove("#userid"); $(this).dialog("close"); } }, { text: "ok", click: function() { $("#passchangeform").submit(); } } ] }); } $("#passchangeform").on("submit", function(e){ e.preventdefault(); var password = document.getelementbyid("chpass1").value; var password2 = document.getelementbyid("chpass2").value; var userid = document.getelementbyid("userid").value; $.ajax({ url: "system/changepass.php", type: "post", data:'pass1='+password+'&pass2='+password2+'&id='+userid, success: function(text){ alert(text); $("#passchangeform").remove("#userid"); $("#changepass").dialog("close"); } }); });
simply use :
$( "#userid" ).remove();
Comments
Post a Comment