event-propagation

Trigger child element's onclick event, but not parent's

妖精的绣舞 提交于 2021-01-27 15:41:30
问题 I've got some nested elements, each with an onclick event. In most cases, I want both events to fire when the user clicks the child (both parent and child events are triggered - default behavior). However, there is at least one case where I want to trigger the child's onclick event (from javascript, not a user's click), but not the parent's. How can I prevent this from triggering the parent event? What I was is: User clicks A: A's onclick fires. User clicks B: B's onclick fires, A's onclick

Real world example where event capturing is necessary / preferred?

谁说胖子不能爱 提交于 2020-01-13 11:42:28
问题 The addEventListener DOM method supports a third optional, boolean parameter (useCapture) to indicate whether the function should use event bubbling or event capturing as propagation method. In this article the difference is nicely shown (click on the examples & view code). From other questions on SO and blog posts, I concluded event bubbling was preferred mostly because IE8- didn't support it. Suppose I'm only required to support IE9+, in what situation would event capturing be necessary or

Javascript/jquery, get all divs location at (x,y). Forwarding touches? [duplicate]

孤街浪徒 提交于 2020-01-12 07:42:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to get a list of all elements that resides at the clicked point? I know I can get the element with the highest z-index by using document.elementFromPoint(x,y) . The problem is I need to get every div that contains the touch event's location. How can I propagate touches to elements underneath? I have seen some hacky solutions that show/hide elements while re-generating the event, or pointer-events style with

event.stopPropagation() not working in chrome with jQuery 1.7

a 夏天 提交于 2020-01-03 17:22:48
问题 For some reason clicking the document isn't working in Chrome (the closeQuickView is not being called). The elements are loaded via AJAX and so need to have .on() action (previously .live() which is now deprecated in jQuery 1.7) Used the example given here: How do I detect a click outside an element? as a basis $('html').on('click', '.poster:not(.active) .image-effect', function (event) { var obj = $(this).parent(); // If there are no .close spans if (obj.find('.close').length === 0) { // Add

Stop event bubbling - increases performance?

对着背影说爱祢 提交于 2020-01-03 12:35:27
问题 If I'm not returning false from an event callback, or using e.stopPropagation feature of jQuery, the event bubbles up the DOM. In most scenarios I don't care if the event bubbles or not. Like with this DOM structure example: ​<div id="theDiv"> <form id="theForm" > <input type="submit" value="submit"/> </form> </div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ Normally, I don't have multiple nested submit callback like this: $('#theDiv').submit

jQuery hotkeys: prevent IE from running its own shortcuts, like Alt+H

血红的双手。 提交于 2019-12-30 07:33:11
问题 Using jQuery hotkeys, I try to bind shortcuts like Alt + H , Alt + C to some specific actions in my site. The event propagation stops (as it should) in all browsers but IE. First of all, is it possible to achieve this? If so, how? Here is a code sample: jQuery(document).bind('keydown', 'Alt+H', function (event) { $this.toggleMenu( 'H' ); if(jQuery.browser.msie) { event.cancelBubble = true; } else { event.stopPropagation(); } return false; } ); In IE, the line $this.toggleMenu( 'H' ); gets

Google Map's Double Click Event Propagation

不羁岁月 提交于 2019-12-30 03:50:12
问题 This question is asked often, but never really answered well. Let's see if we can remedy it! Event Propagation Google allows you to bind to events in a Google Map View via their API using event handlers. Sometimes you may bind your event handler to an event that Google itself is already bound to. Thus, when your event fires and does whatever you told it to do you may find Google also doing its own little thing at the same time. Hmm, can I handle the event so my code runs, but stop the event

Angular 2 Child1-Parent-Child2 event propagating

半城伤御伤魂 提交于 2019-12-25 05:32:23
问题 I am working on Angular 2 for only couple of weeks, so try to be considerate, please, and maybe give me some useful advice? Thank you. I have a main component(pageComponent), that inside its template has other two smaller components(tableComponent and filterComponent), each with its own functions and properties. How do I catch an event created in one of the child components and propagate it to another child component of the same parent? In other words, how to propagate and communicate events

Use jQuery to hide DIV when click outside it, but allow propagation of events

非 Y 不嫁゛ 提交于 2019-12-22 11:35:14
问题 I've read a lot of the other questions involving how to close a div when you click outside of it, but I have a compounded problem in that I have other elements that are bound with .live() What I want to happen is that if I click anywhere else on the page the div should disappear, including if I click on a 'live' element. When I click on that live element I want it's handler to proceed normally. So far as I've read, the basic way to handle closing the div is to attach a click listener to the

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

时光毁灭记忆、已成空白 提交于 2019-12-21 02:59:07
问题 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 cannot have them both called at the same time because the parents event overwrites the event of the child. So I could use event.stopPropagation() so only the first