I wish to set focus to the first element on the page that can accept user input.
Each different page may have an input(text,textarea,Checkbox etc) as the first element, and other pages may have a
select group as the first element.
This works to set focus to the first input element:
I ended up solving my own question, although I still think its clunky.
var $first = $('#filter input, #filter select').first(); // get the first select or input on the page
var type = $first.prop('type');
if (type.search("select") > -1) {
$("select:first:enabled:visible:not(.hasDatepicker)").focus();
} else {
$("input:first:enabled:visible:not(.hasDatepicker)").focus();
}
Member
103 Points
349 Posts
Differentiate Between Select element and Input Element
Feb 14, 2019 10:02 PM|Madog|LINK
I wish to set focus to the first element on the page that can accept user input.
Each different page may have an input(text,textarea,Checkbox etc) as the first element, and other pages may have a select group as the first element.
This works to set focus to the first input element:
This works to set focus to the first select element:
I can't figure out how to get the very first element of either a select or input, and then apply conditional logic to set focus to it correctly.
Thanks
Member
103 Points
349 Posts
Re: Differentiate Between Select element and Input Element
Feb 14, 2019 11:07 PM|Madog|LINK
I ended up solving my own question, although I still think its clunky.