on enter to tab javascript

Solutions on MaxInterview for on enter to tab javascript by the best coders in the world

showing results for - "on enter to tab javascript"
Julieta
11 Oct 2017
1function return2tab (div)
2{
3    document.addEventListener('keydown', function (ev) {
4        if (ev.key === "Enter" && ev.target.nodeName === 'INPUT') {
5
6            var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
7
8            let ol= div.querySelectorAll(focusableElementsString);
9
10            for (let i=0; i<ol.length; i++) {
11                if (ol[i] === ev.target) {
12                    let o= i<ol.length-1? ol[i+1]: o[0];
13                    o.focus(); break;
14                }
15            }
16            ev.preventDefault();
17        }
18    });
19}
20