javascript - Set a reset button to clear a specific single input of type text -
i have following:
<div id="section1"> <label> label 1 </label> <br> <input type="text" id="input_section1"> <button type="reset" class="clear"></button> </div>
this how html must remain structured. have other divs on page same above (called #section2, #section3 etc), , none of inputs within form.
so want button reset specific input associated with; in case above, input '#input_section1'.
at moment when click reset button clearing every input on page.
you can use following jquery code using .siblings()
:
$(document).on('click','.clear',function(){ $(this).siblings( "input" ).val(''); });
this find input type sibling
of current clicked element , reset it.
see fiddle
Comments
Post a Comment