Select all not disabled input buttons
Asked Answered
N

3

22

Can I in some way select all input submit elements that are not disabled?

I can easily find all the disabled ones with: http://api.jquery.com/disabled-selector/

$("input.saveitembtn:disabled")

but is there something a'la:

$("input.saveitembtn:NOTdisabled")

My solution until now is to run through them all with jQuerys .each using .is to check each one individually:

$("input.saveitembtn").each(function(a){
  if( !$(this).is(':disabled') ) {
    ...
  }
});

which I find as total overkill. Is there a simple selector in jQuery?

Nolte answered 6/4, 2013 at 19:1 Comment(0)
D
43

Yes, there is :not()

$("input.saveitembtn:not(:disabled)")
Dardar answered 6/4, 2013 at 19:2 Comment(0)
R
13

Not sure why but the accept answer does not work for me. However this does:

$("input.saveitembtn:not([disabled])");
Rinderpest answered 1/4, 2016 at 18:19 Comment(2)
This is could be the reason (from the jquery-api-doc): "Although their resulting selections are usually the same, the :disabled selector is subtly different from the [disabled] attribute selector; :disabled matches elements that are actually disabled while [disabled] only checks for the existence of the disabled attribute." What the HTML-Standard considers as an "actually disabled" form control can be looked up here: The disabled attribute...Oleograph
@Oleograph - a few years late here but yes, I'm pretty sure when I posted that I was "disabling" an anchor element, so your explanation is spot on.Rinderpest
B
2

Vanilla JavaScript:

const ELS_enabled = document.querySelectorAll("input:not([disabled])");

console.log(ELS_enabled.length); // 2
<input type="text" required placeholder="Required">
<input type="text" required disabled placeholder="Required and disabled">
<input type="text" required placeholder="Required">
Bookbinding answered 13/5, 2021 at 16:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.