jquery - Enable all text fields but not the file field -


i'm trying enable every text field call in function, not want enable type="file" field. happens, type="file" field being enabled anyway. have missed something?

function disabled_fields(fields, state) {     if(state == true) {         $(fields).each(function() {             $(this).attr('disabled', true);         });     } else {         if(state == false) {             $(fields).each(function() {                 if($(this).attr('type') != 'file') {                     $(this).attr('disabled', false);                 }             });         }     } };  // runs disabled_fields('input, textarea', false); 

you can use .not() exclude elements,

function disabled_fields(state) {     $("input,textarea").not("[type='file']").prop("disabled", state); } 

also note that, dont have loop through each elements set disabled property.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -