Re: [jQuery] How to ignore propogated events

2007-03-07 Thread Edwin Martin
Peter Gordon schreef:
> This is the code when the item is clicked.
>
> $("li").bind("click", function(){
>alert( $(this).text() ); event.stopPropagation();
> });
>
> The problem is that when I click on a leaf, not only do I get an event
> for that leaf, but I get an event for each parent.
>
> How can I stop the propogation. I tried event.stopPropagation(), but it
> doesn't seem to do anything.
>   

The event variable is an argument of your function. This should work:

$("li").bind("click", function(evt){
   alert( $(this).text() );
   evt.stopPropagation();
});


Edwin Martin

-- 
http://www.bitstorm.org/edwin/en/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] How to ignore propogated events

2007-03-07 Thread Peter Gordon
Hi.

I am using JQuery 1.1.1

I have the following structure (taken from treeview) and want something
to happen when an  item is clicked. 


  Item 3.0

  Item 3.0.0
   Item 3.0.1
 
   Item 3.0.1.0
   Item 3.0.1.1
   
   
   Item 3.0.2

 Item 3.0.2.0
 Item 3.0.2.1
 Item 3.0.2.2

   
  

   
  



This is the code when the item is clicked.

$("li").bind("click", function(){
   alert( $(this).text() ); event.stopPropagation();
});

The problem is that when I click on a leaf, not only do I get an event
for that leaf, but I get an event for each parent.

How can I stop the propogation. I tried event.stopPropagation(), but it
doesn't seem to do anything.

Thanks for any help.

Peter








___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/