[thelist] Event listener is deaf in Safari

Peter-Paul Koch pp.koch at gmail.com
Mon Jun 6 07:42:44 CDT 2005


> But Safari behaves differently.
> If one cliks on the text of a <li> (its only child), the event
> doesn't bubble up to the parent <li>, and nothing happens. However,
> if one cliks directly on the <li> box (not on the text), the click
> event is correctly processed.
> 
> Event listeners are set to bubble like this:
> object.addEventLister( "click", theFunction, false ), where 'object'
> refers to a <li>.
> 
> Is it a Safari bug, or am I missing something?

It's a bug. According to Safari the target of the click event is the
text node, and not the LI. I didn't know it doesn't bubble up.

Solution:

function theFunction(e)
{
  var tg = (e) ? e.target : window.event.srcElement;
  if (tg.nodeType == 3)
    tg = tg.parentNode;
}

Now tg is the LI the user has clicked on.

-- 
-------------------------------------------------------------------
ppk, freelance web developer

Bug Report: Report bugs yourself, or comment on previously 
reported ones.
http://www.quirksmode.org/bugreports/
------------------------------------------------------------------


More information about the thelist mailing list