Select with jquery all the elements except a specific ID

1

I have an html that can contain several input [submit] dynamically loaded from several php files through includes. The case is that I try that all buttons, by default, remain with the disabled property from the start of the html and until the user does not perform certain operations are not enabled.

At the moment I managed to get all or none of them disabled, but I can not get them all disabled except one of them, with a specific ID, which belongs to the menu where the user can do a search.

var $selects = $('select');
var $buttons = $('input[type="submit"]');


function checkSelect() {

  for ( var n = 0; n < $selects.length; n++ ) {
    //if value of any of the selects is empty disable buttons and return false
    if ( $($selects[n]).val() == 'nulo' ) {
      disableButtons();
      return false;
    }
  }

  enableButtons();
  return true;
}

function disableButtons() {
  for ( var n = 0; n < $buttons.length; n++ ) {
    if ($($buttons[n]).attr('id') != 'btnSearchFilter') {
      $buttons[n].attr('disabled', 'disabled');
    }
  }
}

function enableButtons() {
  $buttons.removeAttr('disabled');
}




$selects.on('change', checkSelect());
$(document).ready(checkSelect());

It's in the line of if ($ ($ buttons [n]). attr ('id')! = 'btnSearchFilter') { where I imagine that this filter should be put, but such which I have it gives me an error indicating that $ buttons [n] .attr is not a function

    
asked by Vera Canet 24.05.2018 в 15:33
source

1 answer

4

jQuery has the expression :not() . I enclose a small demonstration of its use:

$('input:not(#uno)').each(function() {
  console.log(this.value);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="uno" type="text" value="1"/>
<input id="dos" type="text" value="12"/>
<input id="tres" type="text"value="123"/>
    
answered by 24.05.2018 / 15:50
source