event-bubbling

How to prevent default event firing but still allow event to bubble

 ̄綄美尐妖づ 提交于 2019-12-10 12:49:25
问题 Using jQuery: with the following code I'd like to prevent the href url (in this case a hash '#') being fired on click, but still allow the click event to continue bubbling up the chain. How can this be achieved please? <div> <a href="#">Test</a> </div> $('a').click(function(e){ // stop a.click firing but allow click event to continue bubbling? }); 回答1: $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); e.preventDefault() won't

How do I know which element was clicked?

[亡魂溺海] 提交于 2019-12-10 12:08:11
问题 I'm attempting the surprisingly difficult task of finding out which element was clicked. I have these functions from Head First AJAX: function getActivatedObject(e) { var obj; if (!e) { obj = window.event.srcElement; } else if (e.srcElement) { obj = e.srcElement; } else { obj = e.target; } return obj; } function addEventHandler(obj, eventName, handler) { if (document.attachEvent) { obj.attachEvent("on" + eventName, handler); } else if (document.addEventListener) { obj.addEventListener

Binding event handlers to specific elements, using bubbling (JavaScript/jQuery)

匆匆过客 提交于 2019-12-10 11:38:48
问题 I'm working on a project that approximates the functionality of Firebug's inspector tool. That is, when mousing over elements on the page, I'd like to highlight them (by changing their background color), and when they're clicked, I'd like to execute a function that builds a CSS selector that can be used to identify them. However, I've been running into problems related to event bubbling, and have thoroughly confused myself. Rather than walk you down that path, it might make sense just to

Remove event listener with d3js not working

余生长醉 提交于 2019-12-10 11:09:27
问题 I have an SVG structure where there are some shapes inside. I want to fire an event when a shape is clicked and another one when is clicked over the SVG. The problem is the SVG event is always fired. In order to prevent this I'm disabling event bubbling from the shape. Also I've tried to disable the event with d3 but seems to not work. Also tried to disable event with the native Javascript code. An example of the super simple code is: SVG structure <svg id="canvas" xmlns="http://www.w3.org

bubbling in a simple menu using html, css and javascript

旧巷老猫 提交于 2019-12-10 10:27:19
问题 In the code below for a simple menu, if the sub-menu is expanded/showing, then I need the sub-menu to collapse on several conditions: When the main menu or sub-menu LI is clicked When the viewport is larger than the defined minimum width When a click happens anywhere else on the screen Number 2 works and number 1 works as long as I don't declare the addEventListener for the mainMenuID element. For some reason, when I add that event listener for any mainMenuID element, it takes precedence over

jquery focusin() and preventing bubbling

这一生的挚爱 提交于 2019-12-08 14:08:52
问题 UPDATE 2: I slept on it and then whipped up some sample code to try and further figure out the issue. Here's a sample using the console.log of firebug to show you which object is triggering the focusin event: http://jsbin.com/axefo3/11 1) click the first link: yellow div shows 2) hit the tab key: It should tab into the link within the yellow div It does that, but then it triggers the focusin event and, for some reason, it appears to bubble up again to the red div, which is told to then close

INotifyPropertyChanged bubbling in class hierarchy

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 09:45:58
问题 Suppose, I have the following class hierarchy: public NestedClass : INotifyPropertyChanged { string prop1; public String Prop1 { get { return prop1; } set { prop1 = value; OnPropertyChanged("Prop1"); } } void OnPropertyChanged(String name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } public event PropertyChangedEventHandler PropertyChanged; } public Class1 : INotifyPropertyChanged { ObservableCollection

Consume events in MFC's CStatic and pass them to the parent

痞子三分冷 提交于 2019-12-08 04:32:26
问题 I am building MFC application where there is CDialog with child control derived from CStatic on it. I want to receive mouse events for CStatic control so I set "Notify" for it to true. Now I am able to receive message events through message map directly in MyStatic : class CMyStatic : public CStatic { afx_msg void OnLButtonDown(UINT nFlags, CPoint point); // Gets invoked DECLARE_MESSAGE_MAP() } The problem is that from now the parent CDialog is not receiving mouse events when mouse is over

How does event bubbling work on event handling?

心已入冬 提交于 2019-12-07 18:02:55
问题 I have defined this event handler: document.addEventListener("load", function(){ alert("Called on page load"); }, false); I noticed it does not get called when the boolean flag is set to false(fire at bubble phase). Could someone help me out on why this is the case. 回答1: When an event is being sent to an element, it descends the document tree in the capture phase until it reaches the target. Then, if it’s a bubbling event , it bubbles back up. From 2.1 Introduction to “DOM Events” in the DOM

Consume events in MFC's CStatic and pass them to the parent

好久不见. 提交于 2019-12-07 15:23:29
I am building MFC application where there is CDialog with child control derived from CStatic on it. I want to receive mouse events for CStatic control so I set "Notify" for it to true. Now I am able to receive message events through message map directly in MyStatic : class CMyStatic : public CStatic { afx_msg void OnLButtonDown(UINT nFlags, CPoint point); // Gets invoked DECLARE_MESSAGE_MAP() } The problem is that from now the parent CDialog is not receiving mouse events when mouse is over MyStatic child. I can send them from MyStatic manually but is there any way to let them go through