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


Groups > comp.lang.javascript > #8638

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Jörg Weule <weule@7b5.de>
Newsgroups comp.lang.javascript
Subject Re: <ul><li><ul><li>... onclick() only for one node ?
Date Fri, 25 Nov 2011 18:42:18 +0100
Lines 46
Message-ID <9ja2cgFlpkU1@mid.individual.net> (permalink)
References <9j9pfhFe3lU1@mid.individual.net> <1834269.dtTrMRavdF@PointedEars.de>
Reply-To weule@7b5.de
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace individual.net 3F8k2XCtO+DhgqUSbPqy/wB6NlkLr2zgTJTiCylkPC1Aw9zlM8
Cancel-Lock sha1:+YzxPnlzPFT/fbAPFoSYFsR1N5g=
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15
In-Reply-To <1834269.dtTrMRavdF@PointedEars.de>
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:8638

Show key headers only | View raw


thanks for that.

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".

Jörg

On 11/25/2011 05:58 PM, Thomas 'PointedEars' Lahn wrote:
> Jörg Weule wrote:
>
>> at<ul><li><ul><li>...</li></ul></li></ul>  I got the click event on the
>> whole tree and want to process the event for only on one node.
>>
>> How can i stop the event processing calling my function for any node at
>> the hirachie?
>
> If this is really only for one node, you can call the stopPropagation()
> method (standards-compliant) or set the event object's `cancelBubble'
> property to `true' (MSHTML) in the event listener.  However, the drawback of
> this is that *no* element "upwards" in the tree will receive that event
> then, which may not be wanted.
>
> If the latter is important, or if this instead for multiple nodes at the
> same nesting level, you should not do this.  For then you need to stop event
> progagation at every child node.  This comparably inefficient approach is
> propagated by, e. g., jQuery and other selector-based libraries, where you
> would first select elements by a criterion (usually a `class' attribute
> value) and then add an event listener to each matching element.
>
> It is therefore better (for bubbling events like `click') to add only one
> event listener to an ancestor element (here: the `ul' element) in which you
> compare the event target against the object the event has bubbled up to
> (e.target == this, or e.srcElement == this in MSHTML [do not use
> attachEvent()]), and only perform the action for relevant event targets.  In
> case of remaining ambiguity, you can use e. g. the event target's `class'
> attribute value as well.  Be aware that text nodes can be event targets,
> too.
>
>
> PointedEars

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