event.stopPropagation Not Working in Firefox

感情迁移 提交于 2019-12-02 06:35:06

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

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:

  1. classList
  2. dataset
  3. one handler for multiple elements.
  4. css to display and hide thee elements.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!