javascript - How to remove appended element usng jquery? -
i creating form. on submit of form each input field there errorbox appended when input field not filled. want remove or display off errorbox onfocus of input field.while in code remain @ position. tried , went through of similar posts not able find solution. thank you!
html code like
<div class="rowform"> <label for="name">name<span>*</span>:</label> <input type="text" class="mid" name="name" id="name" onfocus="fcs();"/><span id="name_error"></span> </div>
script //on submit of form how appending errorbox
if($("#listcontact #name").val()==""){ $("#name_error").append("<div class='formerror'>please enter name</div>"); }
//the on focus function like
function fcs() { $(".formerror").remove();}
something like:
$(".rowform").on("focus", "input", function(){ $(this).closest(".rowform").find(".formerror").hide(); });
update: indeed no need of event delegation ian said.
$(".rowform").find('[type="text"]').on("focus", function(){ $(this).closest(".rowform").find(".formerror").hide(); });
working fiddle: http://jsfiddle.net/ar7at/
Comments
Post a Comment