A little bg info: I'm working on making a website 100% navigable by keyboard/tabs, and I'm stuck on making the dropdown menus open up when tabbed through.
Here's what I have so far:
<ul class="nav-wrap">
<li class="nav-primary-pg"><a class="selected" href="/">Home</a>
</li>
<li class="nav-primary-pg parent-nav"><a href="/about-us/">About Us<b></b></a>
<ul class="nav-secondary-pg">
<li class="back"><a href="#"></a></li>
<li class=""><a href="/about-us/knowledge-expertise">Knowledge & Expertise</a>
</li>
<li class=""><a href="/why-bank/testimonials">Testimonials</a>
</li>
</ul>
</li>
<li class="nav-primary-pg last-nav-item parent-nav"><a href="/contact-us/">Contact Us<b></b></a>
<ul class="nav-secondary-pg">
<li class="back"><a href="#"></a></li>
<li class=""><a href="/contact-us/application">Apply Now</a>
</li>
<li class=""><a href="/contact-us/quick-quote">Quick Quote</a>
</li>
<li class=""><a href="/contact-us/subscribe">Subscribe</a>
</li>
</ul>
</li>
</ul>
</section>
And for the jQuery:
$("a").each(function (i) { $(this).attr('tabindex', i + 1); });
$('.parent-nav > a').each(function(){
$(this).focus(function() {
$(this).parent().children(".nav-secondary-pg").show();
});
});
Right now, all of my links are getting the tabindex
correctly, and the secondary navigation is showing when the .parent-nav > a
is focused. The problem is getting that function to end when the next .parent-nav > a
is focused. What happens, is I end up with a page that looks like this as I tab through:
How do I kill the function when I reach the next instance in the .each()
?