0

Source element of an event

Hello,

How can I retrieve the source element that fired an event ?

use case: I have several buttons and when one is pressed I want to pass its id to the called function.
code is like this:
var myBtn = new KONtx.control.Button({
id: 'button'+i,
styles: { ... },
events: {
onSelect: function(event) {
log('Button '+id_of_button_that_fired_the_event+' is pressed');
}
}
}).appendTo(this);

I was wondering if the target attribute of a DOMEvent could be this but event.target returns undefined.

Cheers

by
3 Replies
  • QUOTE (cotreaudaubonne @ Apr 28 2009, 01:23 AM) <{POST_SNAPBACK}>
    Hello,

    How can I retrieve the source element that fired an event ?

    use case: I have several buttons and when one is pressed I want to pass its id to the called function.
    code is like this:
    var myBtn = new KONtx.control.Button({
    id: 'button'+i,
    styles: { ... },
    events: {
    onSelect: function(event) {
    log('Button '+id_of_button_that_fired_the_event+' is pressed');
    }
    }
    }).appendTo(this);

    I was wondering if the target attribute of a DOMEvent could be this but event.target returns undefined.

    Cheers


    Inside the code, " this " is in the scope of the button itself, so doing:

    CODE
    this.id


    would give you the id from the button.
    0
  • QUOTE (Jeremy Johnstone @ Apr 28 2009, 02:34 PM) <{POST_SNAPBACK}>
    Inside the code, " this " is in the scope of the button itself, so doing:

    CODE
    this.id


    would give you the id from the button.


    I already tried that but using this.id returns "undefined". Can I email you the file ?
    0
  • QUOTE (cotreaudaubonne @ Apr 29 2009, 12:58 AM) <{POST_SNAPBACK}>
    I already tried that but using this.id returns "undefined". Can I email you the file ?


    Are you including Framework 1.1 or 0.2.2? Feel free to email me the file if you would like me to take a look.

    -Jeremy
    0

Recent Posts

in General - Yahoo! TV Widgets