How do I clear all text fields on a page, deselect buttons etc? I simply want to refresh the page when it loads.. like holding Shift + Refresh?
Give this a try:
$(document).ready(function() {
$('input[type!="button"][type!="submit"], select, textarea')
.val('')
.blur();
});
Clearing the values on buttons and submit buttons will give them a blank label, hence the more complex selector.
If all elements are in form,
then use document.getElementById('your-form-id').reset();
or $('#your-form-id')[0].reset();
Otherwise:
$('input, textarea').each(function() {
this.value = '';
});
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