Reputation: 5791
I have a script to clear all fields but won't remove all the style attributes. How can I remove all the style attributes in the form?
Here is my code:
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}
Upvotes: 1
Views: 307
Reputation: 1857
try this
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
$(this).removeAttr("style");
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}
In general you can remove an attribute in a html tag using the jQuery's removeAttr("your attribute name")...here is more info about removeAttr() JQuery's removeAttr()
Upvotes: 1
Reputation: 7891
just add $(elem).removeAttr("style");
where elem
is the element/selector of the elements you want to remove the style attribute from
Upvotes: 2