jquery - Javascript not working after appending HTML -
i have 4 inputs within form. on click of button, appends 1 more text input form. have delete button right next each input user can delete row if need be. question is, after clicking "add more" button, , appends form , adds new row, delete button doesn't work because javascript doesn't know been added. thought jquery .live() work deprecated apparently.
this what's being added onclick of add more inputs button.
$("#nameinput").append('<tr><td><input type="text" id="name'+ inputnumber +'" class="names" name="name'+ inputnumber +'" placeholder="twitch username..." value="<?php echo $playername5 ?>"> </td> <td><input type="text" id="name'+ inputnumber +'desired" class="desirednames" name="name'+ inputnumber +'desired" placeholder="desired username..." maxlength="20" value="<?php echo $desiredname5 ?>"> </td> <td><a class="btn btn-mini delete" href="javascript:void(0);"><i class="icon-remove-sign icon-large"></i></a></td></tr>'); you can see on third line have class set "delete". javascript isn't recognizing class since information wasn't there when page loaded guess.
this i'm using delete information.
$(".delete").on("click", ".delete", function() { if (confirm("are sure want delete user?")) { $(this).closest("tr").find(".names").val(""); $(this).closest("tr").find(".desirednames").val(""); $(this).closest("tr").fadeout(450); inputnumber-- if (inputnumber <= advancedplan) { $("#addmore").fadein(450); $("#errors").fadeout(450); } } }); edit: nevermind. minor spelling mistake. guys right! help.
you need use jquery's on() method.
$('#nameinput').on('click','.delete',function(){ //do something... });
Comments
Post a Comment