JQuery: How to stop propagation of a bound function not the entire event?

Try someting like this $(mySelector). Click(function(evt) { if (evt. Target == evt.

CurrentTarget) { ///run your code. The if statment will only run this click event on the target element ///all other click events will still run. } }).

I posted my reply as new answer so you can see the HTML. Look below – Dale Jun 4 '10 at 20:52 1 e and evt do not match – Mark Schultheiss Jun 4 '10 at 21:06 @Mark, yeah. @John, some newby may spend hours on that... you may want to edit it for that sake :D – Dale Jun 4 '10 at 21:17.

The suggested solution evt. Target == evt. CurrentTarget is nice, but there are cases where it does not help.

Example: A (suckerfish-style) menu structure with nested ul/li lists. The mousemove event comes from a link inside a list item, which is a child of an ul-list, which is again a child of another list item. Typical for a html menu structure with submenus.

The evt. Target would be the link tag, but we are interested in the mousemove on the list item. Even worse: The link tag could contain span or img tags or other nested stuff.

Then evt. Target would be this span or img. What seems to work here is to catch the event on a parent / root item, and then check the parents of evt.target.

Like this (with jQuery), var $menu = $('div#menu'); $('body'). Mousemove(function(evt){ var element = evt. Target; // find the deepest list item that was affected by this mouseover event.

Var list_item; var in_menu = false; while (element) { if (element == $menu0) { in_menu = true; break; } else if (!list_item && element. TagName == 'LI') { // we found a list item, but we are not sure if we are inside the menu tree. List_item = element; } } // do something with the result.

If (!in_menu) { .. // close all submenus } if (list_item) { .. // open the submenu for this list item. } else { // mouse in menu, but not hovering an item. // leave the submenus open.(?) } }); Maybe some of this could be abbreviated with jQuery like $(evt.

Target).parents(). Is($menu), but I did not get this to work. Also, I would guess that this explicit loop with element.

TagName is faster.

I imagine the performance of having just one slightly more complex $('body').mouseover() will be better than $('li', $menu).mouseover() plus $menu.mouseover() plus $('body').mouseover(). I have not done any benchmarks yet (and little idea how I would start). – donquixote Aug 1 at 1:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions