I am building a sidebar vertical menu that contains Main Menu items and one level of sub-menu items.
I am using Javascript and CSS so that when the user clicks a top-lev
Javascript now..
inline javascript is not a proper way to write code
This example shows a 'innovative' solution to handle a menu.
it also shows you how to correctly handle the event and the event's target.
It uses:
function handler(e){
e=e||window.event;
var target=e.target||e.srcElement;
var action=target.dataset['action']||'no action';
!(action=='toggle')||(target.childNodes[1].classList.toggle('show'));
!target.dataset['url']||alert(target.dataset['url']);
}
var firstUL=document.getElementsByTagName('ul')[0];
firstUL.addEventListener('click',handler,false);
DEMO
http://jsfiddle.net/Jj6FY/1/
the boring stuff is that you need to find the various elements with getEl...
but at the end you have more control over everything.
and here is a accordion function.
http://jsfiddle.net/YjCbM/1/
if you have any questions just ask.
You need to pass the event as an argument to your function.
goTo(event, '#')
Then you can do event.stopPropagation()
and it knows what event is.
http://jsbin.com/OyUvUqa/2