| Page 1 of 1 | [ 3 posts ] |
|
I have an element that i have assigned a click event listener to. When the page loads the event fires.
This is my element: Code: xInnerHtml(li,'<p class="cart" id="unique_id_from_js">blah blah blah</p>'); var tmp = xGetElementById('unique_id_from_js'); YAHOO.util.Event.addListener(tmp,'click',alert('blah')); Every time the page loads it alerts "blah". I even used FireBug and ran the addListener command after the page had already loaded and it immediately alerts. Am I missing something here? If you need the entire JS file I will post it. Thanks! - Ryan |
|
Ryan --
You are not attaching a listener, you are firing a method: This is firing the alert, since it has ()'s around it: Code: YAHOO.util.Event.addListener(tmp,'click',alert('blah')); This will work because it passes a function reference to the listener: Code: YAHOO.util.Event.addListener(tmp,'click', function() { alert('blah'); }); Hope that helps.. |
|
That's great!
You have no idea how long I was racking my brain trying to figure out what I was doing wrong! I even had function () { alert('blah'); } for a while and it still didn't work. Pasted exactly what you had and it worked great! Thanks! |
| 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