Hybrid View
-
17 Oct 2006 6:25 AM #1
YAHOO.ext.Element.addListener problem
YAHOO.ext.Element.addListener problem
On my page i have div tag:
Could you explain me why I can't attach the event to the link with the folowing code:Code:<div id="panel"></div>
Code:var linkTemplate = new YAHOO.ext.DomHelper.Template('{0}'); linkTemplate.compile(); var elem = linkTemplate.overwrite('panel', ['link']); var onClick = function(){alert();} YAHOO.ext.EventManager.addListener(elem, 'click', onClick); YAHOO.ext.Element.get('panel').dom.innerHTML += '';//dummy code, but it is needed in my real situation
-
17 Oct 2006 6:28 AM #2
However, if I write
it works fine.Code:elem.onclick = 'alert();';
-
17 Oct 2006 6:29 AM #3
It may very well be working... alert(); (empty alert) does nothing. Did you try it with something in it?
-
17 Oct 2006 6:35 AM #4
I just copied your exact code into a page (even with empty alert) and it worked perfect.
Is the id "panel" unique on your page?
-
17 Oct 2006 6:42 AM #5
http://www.jackslocum.com/blog/debug/test-it.htm
In IE this works, in FF it throws an exception "not enough arguments". It I add 'Now I work' to alert it works as expected.
-
17 Oct 2006 6:51 AM #6
Sorry, Jack, I changed my first post in this topic while you were answering on it. I've added the following line to the end:
Code:YAHOO.ext.Element.get('panel').dom.innerHTML += '';//dummy code, but it is needed in my real situation
-
17 Oct 2006 6:53 AM #7
You are adding a child element to "panel" via the template, subscribing to click on that child, and then you are overwriting that element using innerHTML. Since the element is gone, there's nothing to trigger the onclick.
-
17 Oct 2006 6:55 AM #8
So, how can I add inner html text correctly?You are adding a child element to "panel" via the template, subscribing to click on that child, and then you are overwriting that element using innerHTML. Since the element is gone, there's nothing to trigger the onclick.
-
17 Oct 2006 6:56 AM #9
By the way, there is a 3rd parameter "returnElement" on all the DomHelper insert/append/overwrite functions now that if you pass true will return a YAHOO.ext.Element instead of raw dom node.
-
17 Oct 2006 6:56 AM #10
Add it to what? The child or the parent?
Similar Threads
-
YAHOO.ext.Element and addListener
By alex1er in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 18 Feb 2007, 2:57 AM -
YAHOO.ext.Element.get
By jclawson in forum Ext 1.x: BugsReplies: 2Last Post: 7 Feb 2007, 10:04 AM -
YAHOO.ext.Element Display
By ojintoad in forum Ext 1.x: Help & DiscussionReplies: 6Last Post: 1 Jan 2007, 2:20 AM -
Updating YAHOO.ext.Element update
By scottw in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 14 Dec 2006, 6:32 AM


Reply With Quote