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


Groups > comp.lang.javascript > #8640

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

Date 2011-11-25 19:11 +0100
From Martin Honnen <mahotrash@yahoo.de>
Organization Liberty Development
Newsgroups comp.lang.javascript
Subject Re: <ul><li><ul><li>... onclick() only for one node ?
References <9j9pfhFe3lU1@mid.individual.net> <1834269.dtTrMRavdF@PointedEars.de> <9ja2cgFlpkU1@mid.individual.net>
Message-ID <4ecfda5e$0$7617$9b4e6d93@newsspool1.arcor-online.net> (permalink)

Show all headers | View raw


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);
   };


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

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