Results 1 to 2 of 2

Thread: How to apply click handler to multiple elements inside a template

  1. #1

    Default How to apply click handler to multiple elements inside a template

    I want to apply a click event to a `span` tag inside a `div` tag.

    HTML Code:
      items: [                                  
     tpl: new Ext.XTemplate(            
     '<div class="test"> Hello world<span class="icon-gear"></span></div>'            
     listeners: {             
     'afterrender': function(this) {                  
     this.el.on('click', this.onClick, this, { delegate: '.test' });               
    'click': function() { this.onSpanClick() }                            

    and below is the click function:

    HTML Code:
        onClick: function (e) {       //some stuff here    },
        onSpanClick: function() {     //some stuff here    }
    now in the above case, when clicked on the container `class="test"`, it goes into the onClick() and works as expected. However when clicked on span element, it still goes to the `onClick()` instead of going to the `onSpanClick()`.
    Is there a way to differentiate between clicks from different elements?


  2. #2
    Sencha User
    Join Date
    Jan 2016


    Event delegation won't work when you have another target inside your delegated target. Are you trying to call both on click of the span?

Similar Threads

  1. [FIXED] Tagfield using plugin to apply template not rendering template
    By KevH in forum Ext JS 6.x Bugs
    Replies: 2
    Last Post: 15 Nov 2016, 7:14 AM
  2. click handler for a link inside a template
    By bhomass in forum Sencha GXT Q&A
    Replies: 7
    Last Post: 17 Dec 2012, 9:00 PM
  3. How to apply text and click handler in button
    By varun.upadhyay in forum Community Discussion
    Replies: 2
    Last Post: 19 Jul 2012, 1:09 AM
  4. Replies: 3
    Last Post: 2 Dec 2011, 8:18 PM
  5. Apply elements to a template after render
    By jp2008 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 30 Apr 2009, 11:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts