How to clear form elements value within specific div using jQuery, i have more than 25 fields in my form, i need function which is clear all type of form elements value. I tried with the basic jQuery function
$('#div_id input[type="text"]').val('');
hi you can use the below code to solve your problem, I hope it is working
function clear_form_elements(id_name) {
jQuery("#"+id_name).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'text':
case 'textarea':
case 'file':
case 'select-one':
jQuery(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}
For all kind of input fields(including select and textarea) try the :input-selector
$('#div_id :input').val('');
Your selector will clear only those input element which as an explicit type="text" set, meaning <input name="abc" /> will not be cleared
$('#div_id *').val('');