Skip to content

Instantly share code, notes, and snippets.

View Veyfeyken's full-sized avatar

Gijs Veyfeyken Veyfeyken

View GitHub Profile
@drublic
drublic / keep-focus.js
Last active March 29, 2017 15:20
A function that lets you circularly tab through a part of a page.
var tabbableElements = 'a[href], area[href], input:not([disabled]),' +
'select:not([disabled]), textarea:not([disabled]),' +
'button:not([disabled]), iframe, object, embed, *[tabindex],' +
'*[contenteditable]';
var keepFocus = function (context) {
var allTabbableElements = context.querySelectorAll(tabbableElements);
var firstTabbableElement = allTabbableElements[0];
var lastTabbableElement = allTabbableElements[allTabbableElements.length - 1];
@Zegnat
Zegnat / README.md
Created February 24, 2012 12:03
Fixing your skip links. [JS]

Fixing your skip links.

Read Damon Muma on this. He proposes the following jQuery solution (inspired by Thompson, fixed by me):

// Apply focus properly when accessing internal links with keyboard in WebKit browsers.
$("a[href^='#']").not("a[href='#']").click(function() {
   $("#"+$(this).attr("href").slice(1)+"").focus();
});