onclick not return element id

Game development with Board Game Arena Studio
Post Reply
User avatar
Fefay
Posts: 8
Joined: 21 March 2019, 17:04

onclick not return element id

Post 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..
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: onclick not return element id

Post by DrKarotte »

What does it alert?

You use "evt.currentTarget.id"?
User avatar
Galeelox
Posts: 17
Joined: 14 March 2017, 12:17

Re: onclick not return element id

Post by Galeelox »

Did you declare your 'onclick' event AFTER the creation of the element you click on?
User avatar
Fefay
Posts: 8
Joined: 21 March 2019, 17:04

Re: onclick not return element id

Post 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 {}
User avatar
RicardoRix
Posts: 2541
Joined: 29 April 2012, 23:43

Re: onclick not return element id

Post 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));
            },
User avatar
Lymon Flowers
Posts: 195
Joined: 01 April 2020, 21:14

Re: onclick not return element id

Post 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
User avatar
Fefay
Posts: 8
Joined: 21 March 2019, 17:04

Re: onclick not return element id

Post 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
Post Reply

Return to “Developers”