Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know if <code>&lt;li&gt;</code> can get (keyboard) focus programmatically, but I can <a href="http://jsfiddle.net/YdKtz/1/" rel="nofollow">show you how to change classnames</a> programmatically.</p> <p>[<strong>edit</strong> based on comment] If it's hrefs you mean, <a href="http://jsfiddle.net/PgMcL/" rel="nofollow">here</a> is a working example. Use tab to jump to the next href.</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict"; (function () { var refs = document.getElementsByTagName('a'); document.addEventListener('focus', hoverClass, true); refs[0].focus(); setTimeout(emulateHover, 800); function emulateHover() { if (!document.activeElement.href) {return clearTimeout(0);} var index = parseInt(document.activeElement.href.split(/#/)[1], 10); var activeElement = refs[index] || refs[0]; if (activeElement) { activeElement.focus(); } setTimeout(emulateHover, 800); } function hoverClass(evt){ var srcEl = evt.srcElement || evt.target; var i = refs.length; while(i--) { refs[i].className = 'a'; } if (srcEl &amp;&amp; !/a/i.test(srcEl.tagName)) { return clearTimeout(0); } var isA = /a$/i.test(srcEl.className); srcEl.className = isA ? 'b' : 'a'; } }());</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { font: normal 12px/15px verdana, arial; } .a {background-color: #eee; transition: all 0.5s 0s} .b {background-color: green; color:white; transition: all 0.5s 0s} a {text-decoration: none;}</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ul&gt; &lt;li&gt;&lt;a id="first" class="a" href="#1"&gt;line 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="a" href="#2"&gt;line 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="a" href="#3"&gt;line 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="a" href="#4"&gt;line 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="a" href="#5"&gt;line 5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="a" href="#6"&gt;line 6&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload