I have got a input field where in user enters data. There are 2 buttons next to it upon click any one of them or both the input fields get reset. Now since these buttons and field is not inside a form I can't go for a instead how can i clear it with JQuery. The point is, now I have displayed only 2 buttons, the JQuery must also work if there where more buttons..Fiddle link below and the code i tried
$('button').each(function(){
$('button').click(function(){
find('input[type="text"]').val() = "0";
});
});
[Fiddle link] http://jsfiddle.net/vineetgnair/1s22gcL5/
Thanks to all for help.
This will work:
$('button').click(function(){
$('input[type="text"]').val(0);
});
If you want to just reset field then :
$('button').click(function(){
$('input[type="text"]').val('');
});
No need of saying each, just say .click
it will apply for every button
$('button').click(function(){
$('input[type="text"]').val(0);
});
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With