Page 1 of 1

onclick not return element id

Posted: 14 May 2020, 22:26
by Fefay
Hello

I've a problem with an event.
I connect onclick on my method, and i just want to alert the currentTarget.id
It works on other action, but not on this new..

Re: onclick not return element id

Posted: 15 May 2020, 12:10
by DrKarotte
What does it alert?

You use "evt.currentTarget.id"?

Re: onclick not return element id

Posted: 15 May 2020, 12:15
by Galeelox
Did you declare your 'onclick' event AFTER the creation of the element you click on?

Re: onclick not return element id

Posted: 15 May 2020, 22:24
by Fefay
my element is on interface, and i connect the action

Code: Select all

dojo.query('.' + notif.args.player_id + 'Tile').connect('onclick', this, 'onSelectWorshiper');

Code: Select all

onSelectWorshiper: function (evt) {
                // Stop this event propagation
                dojo.stopEvent(evt);

                alert(JSON.stringify(evt.currentTarget));
            },
Alert dialog show {}

Re: onclick not return element id

Posted: 16 May 2020, 00:32
by RicardoRix
Add the line: debugger; and hit F12; then click the target.
Hover over the 'evt' variable to analyse it.

Code: Select all


onSelectWorshiper: function (evt) {
                // Stop this event propagation
                dojo.stopEvent(evt);

		debugger;
                alert(JSON.stringify(evt.currentTarget));
            },

Re: onclick not return element id

Posted: 16 May 2020, 10:11
by Lymon Flowers
Fefay wrote: 15 May 2020, 22:24

Code: Select all

dojo.query('.' + notif.args.player_id + 'Tile').connect('onclick', this, 'onSelectWorshiper');
Are you sure about this? I think you should use 'click' and not 'onclick' with dojo.connect.

Benjamin

Re: onclick not return element id

Posted: 27 May 2020, 22:02
by Fefay
Thank you for your help

Debugger show the good value
The alert never show data of event.

I can use evt.currentTarget.id in the code