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

  • SEARCH
  • Home
  • 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 3402554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:09:08+00:00 2026-05-18T05:09:08+00:00

When the user clicks on this element, I want it to show an alert.

  • 0

When the user clicks on this element, I want it to show an alert.

However, when I click on the DIV that this Panel generates, nothing happens.

How can I make an alert execute when the user clicks on the following panel?

var content = new Ext.Panel({
    region:'center',
    margins:'5 0 5 5',
    cls:'empty',
    bodyStyle:'background:ivory; font-size: 13pt',
    html:'<p id="test123">This is where the content goes for each selection.</p>',
    click: function() {
        alert('was clicked');
    }
});
  • 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-05-18T05:09:09+00:00Added an answer on May 18, 2026 at 5:09 am

    You haven’t accepted an answer, so I’ll assume you’re still unclear on this. Here are a few pointers…

    First, as coded your Panel will render as a plain square. If you’re expecting it to look like a Panel, you should give it a title (so the title bar will render).

    Second, as mentioned, click is not a Panel event (it’s an Element event). So you have several ways of getting to the behavior you want. You can manually attach a listener to the underlying DOM element after the Panel is rendered:

    Ext.get('txest123').on('click', function(){
        alert('foo');
    });
    

    You could also do as I mentioned in the comments of another answer to generically handle any body click:

    // .body is a Panel property for the body element
    content.body.on('click', function(){
        alert('foo');
    });
    

    If you really want to restrict the click to only the child p you could add a check:

    // e is the event object, t is the target DOM node
    content.body.on('click', function(e,t){
        if(t.id == 'txest123'){
            alert('clicked the p');
        }
    });
    

    If I was coding this, I’d probably do something more like this:

    var content = new Ext.Panel({
        region:'center',
        renderTo: document.body,
        margins:'5 0 5 5',
        cls:'empty',
        title: 'My Panel',
        id: 'txest123',
        bodyStyle:'background:ivory; font-size: 13pt',
        html:'This is where the content goes for each selection.',
        listeners: {
            'render': {
                fn: function() {
                    this.body.on('click', this.handleClick, this);
                },
                scope: content,
                single: true
            }
        },
        handleClick: function(e, t){
            alert(this.id); // the panel
            alert(t.innerHTML); // the clicked el
        }
    });
    

    Now the id is on the Panel (where it should be) and you can use Panel and/or Element methods to access child elements as needed. It’s best to keep id’s at the highest level possible. You’ll notice too that the callback function is executed in the scope of the Panel (scope:this) so that inside handleClick you can treat this as the Panel itself and access any of its properties or methods.

    So, without knowing exactly what you’re trying to achieve, I can’t provide you with the exact code you need. However, this should hopefully give you some ideas.

    EDIT: I meant to say this originally… in your code (as posted) you are not actually rendering the Panel. As I mentioned in my answer to your related question, if you are adding the Panel as an item to a container that is lazy-rendered, the Panel’s DOM won’t be available for selection until after the container has rendered it. In my code above I added renderTo so that I don’t have this issue, but if you’re not doing that you’ll have to wait until the Panel is rendered at some time later to access it.

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

Sidebar

Related Questions

I am trying to use jQuery to show a div when the user clicks
Example: The user login to the webpage => Click on a button This action
I want to close a System.Windows.Forms.Form if the user clicks anywhere outside it. I've
In my ASP.Net application I have a requirement that when a user clicks on
I want to disable the default contextMenu when a user right-clicks on an input
I wrote a code to show a div element(shareform) when a link is clicked
I'm trying to make a notification area that will show alerts. return this.each(function() {
http://jsfiddle.net/M6xdq/ What I want to achieve, is - when user clicks the read more
$(function() { $(.follow).click(function(){ var element = $(this); var I = element.attr(id); var info =
I want to implement a show more paginator inside of a jQuery tab panel.

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.