1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    36
    Vote Rating
    0
    kovtik is on a distinguished road

      0  

    Default YAHOO.ext.Element.addListener problem

    YAHOO.ext.Element.addListener problem


    On my page i have div tag:
    Code:
    <div id="panel"></div>
    Could you explain me why I can't attach the event to the link with the folowing code:
    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

  2. #2
    Ext User
    Join Date
    Mar 2007
    Posts
    36
    Vote Rating
    0
    kovtik is on a distinguished road

      0  

    Default


    However, if I write
    Code:
    elem.onclick = 'alert();';
    it works fine.

  3. #3
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    It may very well be working... alert(); (empty alert) does nothing. Did you try it with something in it?

  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    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?

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    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.

  6. #6
    Ext User
    Join Date
    Mar 2007
    Posts
    36
    Vote Rating
    0
    kovtik is on a distinguished road

      0  

    Default


    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

  7. #7
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    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.

  8. #8
    Ext User
    Join Date
    Mar 2007
    Posts
    36
    Vote Rating
    0
    kovtik is on a distinguished road

      0  

    Default


    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.
    So, how can I add inner html text correctly?

  9. #9
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    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.

  10. #10
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Add it to what? The child or the parent?

Similar Threads

  1. YAHOO.ext.Element and addListener
    By alex1er in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 18 Feb 2007, 2:57 AM
  2. YAHOO.ext.Element.get
    By jclawson in forum Ext 1.x: Bugs
    Replies: 2
    Last Post: 7 Feb 2007, 10:04 AM
  3. YAHOO.ext.Element Display
    By ojintoad in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 1 Jan 2007, 2:20 AM
  4. Updating YAHOO.ext.Element update
    By scottw in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 14 Dec 2006, 6:32 AM

Thread Participants: 1