| Page 1 of 1 | [ 3 posts ] |
|
Hi all,
I am having trouble with executing the call back function for an attached event. I use the getListeners() function to return the click event listener that I have attached to the control via Event.addListener(). When the results of the getListeners() call is dumped into the FireBug console it shows the fn property as having the function assigned to it, however when I try to execute it I get the error clickListener.fn is not a function. I have posted a example of what I am trying to achieve below. I am using FF3 and Chrome. Any one got any ideas as to why this happens? Thanks in advance.. Code: <html> <head> <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script> <script> var namespace = function() { YAHOO.util.Event.addListener(window, "load", Init); function Init() { YAHOO.util.Event.addListener("cmdClickMe", "click", cmdClickMe_Click); YAHOO.util.Event.addListener("cmdClickOther", "click", cmdClickOther_Click); } function cmdClickMe_Click(oArgs) { alert("You clicked me!"); } function cmdClickOther_Click(oArgs) { var clickListener = YAHOO.util.Event.getListeners("cmdClickMe", "click"); clickListener.fn(); // throws the error: clickListener.fn is not a function } }(); </script> </head> <body> <input type="button" id="cmdClickMe" value="Click Me" /> <input type="button" id="cmdClickOther" value="Click 'Click Me'" /> </body> </html> |
|
getListeners returns an array:
Code: function cmdClickOther_Click(oArgs) { var clickListeners = YAHOO.util.Event.getListeners("cmdClickMe", "click"); clickListeners[0].fn(); } |
|
Thanks Adam,
Worked a treat. Something so simple has had me pulling my hair out for quite some time. |
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group