JQuery: no and: first order

I am trying to get the first input field in a form that is not disabled or hidden. I need to be able to exclude switches, select specific identifiers.

The following code works fine, EXCEPT, when the selection appears before the text or password I want:

$("form :input:visible:enabled:first:not('select')"); 

If I exclude: not ('select'), the selection is returned as the first input field (correct, since: input returns almost all form elements). However, when I include: not ('select'), nothing happens. Any ideas?

The second part to this question is - I assume this is normal for the: nots chain, so I could be something like:

 $("form :input:visible:enabled:first:not('select'):not(#specific_id):not(type[radio])"); 
+4
source share
3 answers

Will it work if you replace :not and :first ?

 `$("form :input:visible:enabled:not('select'):first");` 

As you have it, it selects the first activated tag, which contains only one. If this is one of them, you won’t get anything. With this version, he gets everything that is not selected, and then takes the first element of this set.

+7
source

Using the Tesserex answer, you can also join several not.

 $("form :input:visible:enabled:not('select, :radio, #id, .class'):first"); 

Just separate with commas, as in any other jQuery tag.

+2
source

it would be better to use 'type=select' or 'type=xxx' in this case, rather than the ': not' selector.

you can use the .is() function.

0
source

Source: https://habr.com/ru/post/1315441/


All Articles