event-propagation

JavaScript: event.preventDefault() vs return false

When I want to prevent other event handlers from executing after certain event is fired I can do one of those (jQuery examples, but this will work in JS in general): #1 event.preventDefault() $('a').click(function (e) { // custom handling here e.preventDefault(); }); #2 return false $('a').click(function () { // custom ...

How do I prevent a parent's onclick event from firing when a child anchor is clicked?

I'm currently using jQuery to make a div clickable and in this div I also have anchors. The problem I'm running into is that when I click on an anchor both click events are firing (for the div and the anchor). How do I prevent the div's onclick event from firing when an anchor is clicked? Here's the broken code: JavaScript var url = $...

JavaScript: Is there any performance benefit to stopping event propagation?

Is it considered 'good practice' to stop JavaScript event propagation - does it benefit performance in any way? I'm wondering if there is benefit outside of layout purposes where you stop propagation so you don't trigger multiple events accidentially. ...

Event propagation in Javascript

If I have an element (html) nested in another element and both of them have a click handler attached, clicking the inner element executes its click handler and then bubbles up to the parent and executes its click handler. That's how I understand it. Do events bubble up the DOM tree if there are no events attached that are the same and i...

Excluding form fields from keypress handler assigned to body

I have a keypress handler on a web page assigned to the body element. I really do want it to be active anywhere in the web page. Or so I thought. The keypress events in textual input forms also activate the body handler, which makes sense, but which I don't want. Ideally, I'd like to keep the keypress handler assigned to the body ele...

Reassigning the click event from click (using jQuery)

Hi everyone! I'm having some trouble with this javascript (using jQuery): $(a).click(function(){ alert('hi') this.unbind.click(function(){ doSomethingElse(this); }) }) When a is clicked, it is supposed to reassign its own click event. Unfortunately, it fires the second click event as well. I know this is to do with p...

What are the advantages/disadvantages of Local Peer Message Propagation over event aggregator?

http://msdn.microsoft.com/en-us/magazine/cc700336.aspx#id0090029 http://msdn.microsoft.com/en-us/library/system.servicemodel.peermessagepropagation.aspx ...

Javascript Event Bubbling Not Working As Expected

Hi Guys, Having a nightmare trying to figure out event Bubbling.. Full test case: <html> <head> <script type="text/javascript"> function $(ob) { return document.getElementById(ob) } function bodyClick() { $('win_clicks').value = parseInt($('win_clicks').value) + 1; } window.addEventListener('load',function(e) { $('bl_lnk').ad...

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

I have a click function bound to many elements. It is possible that sometimes these elements may sit within one another. So, the click event is bound to a child and also bound to its parent. The method is specific to the element clicked. Naturally, because of event bubbling, the child's event is fired first, and then the parents. I ca...

jQuery : give preference to inner click

I have a big div with some links inside, I'd like to have the big div clickable AND links inside too, I did this : html : <div class="clickable"> some text... <a href="myurl1">Link 1</a> <a href="myurl2">Link 2</a> some text... </div> jquery : $('.clickable').click(function() { alert('Hello'); }); If I click on a link in...

One click handler for multiple buttons and stop propagating event up to parent?

Hi, I'm generating a bunch of "li" items as a result of an ajax call. They look like: <li> <p>Hello result 1</p> <button>remove</button> </li> <li> <p>Hello result 2</p> <button>remove</button> </li> ... can I create a single click handler that will get called when any one of the "li" item "button" elements gets clicked, ...

Propagate custom QEvent to parent widget in Qt/PyQt

Fist, apologies for the length of the question. I am trying to propagate custom Qt event from child widgets to a top parent widget in order to trigger some action based on event type instead of linking signals. Qt docs suggests that every event posted with postEvent() that have accept() and ignore() methods can be propagated (meaning e...

Propagation of events in a collection based project

I have a collection-based project in .NET 4. What I mean is that, I have a master collection, call it "System", which is made up of frames, which are each made up of cards, which are in turn made up of channels. So, it looks like System->Frame->Card->Channel. All these are represented as objects, and there is a Parent-Child relationship ...

jQuery stop click event from bubbling when using $.get()

Hi All, I have assigned a click event to a button, which retrieves a different HTML snippet and injects it into a DIV element using the .html(string) method. $('#btnClose').click(function(){ $.get('Content.html',function(data) { $('#EditCategory').html(data); }); }); The Content.html page is as follows: <button id="b...

How to disable some element reaction to any mouse event without interrupting underlaying element events in jQuery?

Hi. I'm trying to make a simple pop-up <div> that's designed to show mouse coordinates while a user is dragging a mouse pointer. This pop-up appears at the bottom on the right to the mouse pointer. The underlaying div has its own very important mouse event handlers (e.g. .mousemove()). The pop-up div is quite far away from the mouse poi...