Wanted: “Super selector” or “How to focus the first visible input field” that doesn't matter?

I was wondering if it is possible to focus the field of the first empty visible "input" with only one jQuery selector : something like $('superamazingselector').focus();

With input fields, I mean: text areas, inputs (rather than type = "hidden"), selects, radio buttons, unchecked checkboxes. I think this "super selector" will be very convenient on many pages.

+4
source share
3 answers

Try this one (untested):

 $(':input[value=""]:visible:not(:button):first, :checkbox:not(:checked):first').first().focus(); 

How you choose the radio buttons depends on your HTML structure for <input type="radio" /> , I can't come up with a one-bit type selector that detects an unselected group of radio buttons.

+7
source

Good question:

Try:

 $(':input[value=""]:visible:first').focus(); 
+3
source

I think $(":input:visible[value='']").first() should do this.

example: http://www.jsfiddle.net/U3r6C/1/

+2
source

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


All Articles