1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    34
    Vote Rating
    1
    Dbms is on a distinguished road

      0  

    Default Answered: Do Event Listeners take space in DOM?

    Answered: Do Event Listeners take space in DOM?


    Hi,

    Case: I have 5 containers inside vbox layout in a parent container. I attach listeners for tap event on each of the 5 child containers. Another way proposed is to add one event listener on the parent container, because apparently it lightens the DOM.

    Questions:
    1. Do Event Listeners take space in DOM?
    2. If I put the event listener on the parent container only, how do I know which child container was clicked?

  2. Event listeners do not take up space in the DOM. They will take up some space in memory. If you can use just 1 listener then you will get a small performance increase over using 5 listeners.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,217
    Answers
    3519
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Event listeners do not take up space in the DOM. They will take up some space in memory. If you can use just 1 listener then you will get a small performance increase over using 5 listeners.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    34
    Vote Rating
    1
    Dbms is on a distinguished road

      0  

    Default Suggestion For Second Question?

    Suggestion For Second Question?


    Hi Mitchell,

    Thanks for the answer. Can you suggest anything for the second question also?

  5. #4
    Sencha User
    Join Date
    May 2013
    Location
    Roseville, CA
    Posts
    1
    Vote Rating
    0
    olafcalderon is on a distinguished road

      0  

    Default Event Listeners

    Event Listeners


    jQuery('.wrapper').on('click', function(event) {
    var wrap = jQuery(this);
    // wrap is now the jquery object of the wrapper

    var el = jQuery(event.target);
    // el is now the jquery object that was clicked on

    if (el.is('#mydiv')) {
    // do something here if the item clicked is #mydiv
    alert('this is #mydiv');
    }
    if (wrap.hasClass('elementclass')) {
    // do something here if the wrapper of the item clicked has class of 'elementclass'
    alert('this is inside .elementclass');
    }
    });

    Here's some code as to when this would apply:

    <div id='container1' class='wrapper'>
    <ul>
    ...
    </ul>
    <div id='mydiv'>
    ...
    </div>
    </div>

    <div id='container2' class='elementclass'>
    <ul>
    ...
    </ul>
    <div id='mydiv2'>
    ...
    </div>
    </div>

    if you had #mydiv inside .elementclass then two alerts would fire.


    hope that helps!