javascript trap focus
/**
*Function should be called on keyPress or something
*/
function _focusTrapperEvent(e) {
if (!(e.key === 'Tab' || e.keyCode === 9))
return;
let condition = 'a[href], area[href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object:not([disabled]), embed, *[tabindex], *[contenteditable]',
first = $('.focusKeeper').find(condition).filter(':not(.select-element):visible:not(.invisible):first'),
last = $('.focusKeeper').find(condition).filter(':not(.select-element):visible:not(.invisible):last');
console.log(first);
console.log(last);
if ( e.shiftKey ) /* shift + tab */ {
if (document.activeElement === first[0]) {
last[0].focus();
e.preventDefault();
}
} else /* tab */ {
if (document.activeElement === last[0]) {
first[0].focus();
e.preventDefault();
}
}
}
Also in JavaScript:
- query selector click event
- angular 8 to 9
- require is not defined
- input show validation message
- what is foreach method in javascript
- pass header in ajax
- input type date doesn't work in ie
- comments in js
- select onchange jquery get the selected option data attribute
- new features of angular 11
- get selected option value jquery
- convert date time to string javascript
- user agent chrome
- JavaScript how do you create a screen pressable button in 10 lines?
- jquery check if clicked outside div
- javascript on script loaded
- javascript base64 encode string
- How to access the request body when POSTing using Node.js and Express
- email validation in javascript
- how to define connection string in appsettings.json
- : Cannot set the body fields of a Request with content-type "application/json".
- list pci express version command line
- output event angular
- nodejs read file to array