Greetings, Its been awhile since I've posted here, but I've come seeking help again.
With my limited knowledge of javascript I've been working on a script to make a dropdown menu accessible using the keyboard. I've gone as far as I can and realized I'm in over my head. I don't know where to go from here to keep the appropriate submenus open when the anchor in the parent level loses focus. Simply replacing the className again onblur obviosly won't work.
Any help is much appreciated, thank you.
Code:function menuHide() { var a = document.getElementById("nav").getElementsByTagName("a"); for (var x = 0; x < a.length; x++) { var li = a[x].parentNode; while (li.nodeName != 'LI') li = li.parentNode; if (li.childNodes.length > 1) { for (var y = 0; y < li.childNodes.length; y++) { if (li.childNodes[y].nodeName == 'UL') li.className += " js-hide"; } } li.onmouseover = function() { if(/\bjs-hide\b/.test(this.className)) this.className = this.className.replace("js-hide", "js-show"); } li.onmouseout = function() { if(/\bjs-show\b/.test(this.className)) this.className = this.className.replace("js-show", "js-hide"); } a[x].onfocus = function() { var thisLi = this.parentNode; while (thisLi.nodeName != 'LI') thisLi = thisLi.parentNode; if(/\bjs-hide\b/.test(thisLi.className)) thisLi.className = thisLi.className.replace("js-hide", "js-show"); } // a[x].onblur = function() {} } } window.onload = menuHide;



Reply With Quote


Bookmarks