javascript - how to access the elements which created using the jquery insertAfter method -
i have select tag when change i'm showing input user , when user change select tag multiple times element insert after each other want remove old input after changing select tag , insert new related input.
just keep track of reference element then...
var element; $("#sel").change(function () { var sel = $(this); if(element)//check if input has been created element.remove();//remove old input dom element = $("<input/>").val(sel.val());//create new input , store reference element.insertafter(sel);//insert new input dom }); $("#sel").change();
because insertafter
function of element creating, must creating reference in current code anyway. need store reference globally. each time change select, can check if reference has value , remove dom.
Comments
Post a Comment