Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8643

Re: <ul><li><ul><li>... onclick() only for one node ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <2567763.1uUHiEQOGO@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Fri, 25 Nov 2011 20:04:42 +0100
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
Subject Re: <ul><li><ul><li>... onclick() only for one node ?
Newsgroups comp.lang.javascript
References <9j9pfhFe3lU1@mid.individual.net> <1834269.dtTrMRavdF@PointedEars.de> <9ja2cgFlpkU1@mid.individual.net> <4ecfda5e$0$7617$9b4e6d93@newsspool1.arcor-online.net>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 64
NNTP-Posting-Date 25 Nov 2011 20:04:43 CET
NNTP-Posting-Host ef7c8a3b.newsspool2.arcor-online.net
X-Trace DXC=3FaJIe;7mGmj5k5aEF7ISmA9EHlD;3Ycb4Fo<]lROoRa8kF<OcfhCOkL9HoAM`Ej_oDZm8W4\YJNl;?f@h5gMfbl>@dMN77i@Ha=d?Wb^FdmTa
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:8643

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Martin Honnen wrote:

> Jörg Weule wrote:
>> Not I can write <div onClick()="doMyFunction(event.target)"> to get the
>> inner clicked element but Firefox is not accepting
>>
>> var l = document.createElement("li");
>> l.onclick = function(){ doMyFunction(event.target) ; } ;
>>
>> Here I got "event is not defined".
> 
> The proper approach is
>    var l = document.createElement("li");
>    l.onclick = function(evt) {
>      doMyFunction(evt.target);
>    };
> at least for Mozilla, Opera, Safari, Chrome and IE 9 (in IE 9 mode).
> For earlier IE versions you need
>    var l = document.createElement("li");
>    l.onclick = function(evt) {
>      var event = evt || window.event;
>      doMyFunction(event.target || event.srcElement);
>    };

If one uses the more error-prone boolean shortcut syntax instead of `typeof' 
testing, it should be

     l.onclick = function(evt) {
       var event = evt || window.event;
       if (event)
       {
         doMyFunction(event.target || event.srcElement);
       }
     };

as one should not assume that if `evt' type-converts to false, 
`window.event' must refer to an object.  However, that approach is 
proprietary, even though for historical reasons it is probably most 
compatible.

The standards-compliant approach is, and the proper approach has become

     l.addEventListener("click", function(evt) {
       doMyFunction(evt.target);
     }, false);

since IE/MSHTML 9 supports it in Standards Mode.  Until that remains less 
compatible (there is still IE/MSHTML < 9), using a wrapper method like 
jsx.dom.addEventListener() [1] is recommended, so as not to overwritethe 
primary event listener if one has been added, e. g., with the `onclick' 
attribute, and not to interfere with the order of event listeners of an 
element.


PointedEars
___________
[1] 
<http://pointedears.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fdom%2Fevents.js>
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

<ul><li><ul><li>... onclick() only for one node ? Jörg Weule <weule@7b5.de> - 2011-11-25 16:10 +0100
  Re: <ul><li><ul><li>... onclick() only for one node ? Arno Welzel <usenet@arnowelzel.de> - 2011-11-25 17:30 +0100
  Re: <ul><li><ul><li>... onclick() only for one node ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-25 17:58 +0100
    Re: <ul><li><ul><li>... onclick() only for one node ? Jörg Weule <weule@7b5.de> - 2011-11-25 18:42 +0100
      Re: <ul><li><ul><li>... onclick() only for one node ? Martin Honnen <mahotrash@yahoo.de> - 2011-11-25 19:11 +0100
        Re: <ul><li><ul><li>... onclick() only for one node ? Jörg Weule <weule@7b5.de> - 2011-11-25 19:37 +0100
        Re: <ul><li><ul><li>... onclick() only for one node ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-25 20:04 +0100
  Re: <ul><li><ul><li>... onclick() only for one node ? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-25 20:27 +0200
    Re: <ul><li><ul><li>... onclick() only for one node ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-25 20:28 +0100
      Re: <ul><li><ul><li>... onclick() only for one node ? "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-25 21:57 -0200
        Re: <ul><li><ul><li>... onclick() only for one node ? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-26 09:14 +0200
          Re: <ul><li><ul><li>... onclick() only for one node ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-26 12:53 +0100
        Re: <ul><li><ul><li>... onclick() only for one node ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-26 12:51 +0100

csiph-web