Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:55:03+00:00 2026-06-02T19:55:03+00:00

How can one assign a click event to an arbitrary span ( eg. <span

  • 0

How can one assign a click event to an arbitrary span (eg. <span id="foo">foo</span>) in an ST2 app?

I have a trivial example that illustrates the idea of what I’d like to do. In the example, I write the letters A,B,C and I’d like to tell the user which letter they clicked.

Here’s an image:

enter image description here


CODE SNIPPET

Ext.application({

    launch: function() {
        var view = Ext.create('Ext.Container', {

            layout: {
                type: 'vbox'
            },
            items: [{
                html: '<span id="let_a">A</span>  <span id="let_b">B</span> <span style="float:right" id="let_c">C</span>',
                style: 'background-color: #c9c9c9;font-size: 48px;',
                flex: 1
            }]
        });
        Ext.Viewport.add(view);
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:55:05+00:00Added an answer on June 2, 2026 at 7:55 pm

    You can add a listener to a specific element using delegation. It is actually fairly simply to use.

    Ext.Viewport.add({
        html: 'test <span class="one">one</span> hmmm <span class="two">two</span>',
        listeners: [
            {
                element: 'element',
                delegate: 'span.one',
                event: 'tap',
                fn: function() {
                    console.log('One!');
                }
            },
            {
                element: 'element',
                delegate: 'span.two',
                event: 'tap',
                fn: function() {
                    console.log('Two!');
                }
            }
        ]
    });
    

    The main parts are element and delegate.

    • element will have the value of element in almost every case, unless you are working with custom components with custom templates.
    • delegate is a simple CSS selector. So it could be anything from span to span .test.second

    Ideally, as Thiem said, you should take advantage of components as much as possible. They will give you much more flexibility. But I know there are definitely some cases where you need to do this. There will be no performance implications; in fact, it will be faster than using components. However, you should never implement listeners the way he suggested. It will not be performant and is extremely dirty (as he mentioned).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can one programmatically determine logins/users that have permission to access specific SSRS reports?
I just learned that an object can have only one ID, so I'm not
Can one place an arbitrary program (firefox, openoffice, etc...) in a QX11EmbedContainer? The fllowing
How can one have more than a Wizard control on the same page without
I'm trying to delegate a click event to a TR element that contains a
I have a form that can be manipulated on the client's browser via javascript
I am to build a web app and I have realized that my domain
I have some elements with a function bound to the click event. I want
I got a table and i assign the click event via .live() to each
Please help me: create clickable regions in the canvas below that I can assign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.