Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Accessing sender in JS anonymous event handlers
- jvvg
-
1000+ posts
Accessing sender in JS anonymous event handlers
I'm trying to dynamically create a button in JS, and the onclick function requires the sender.
The code runs when a certain action is triggered and looks like this:
I want to be able to access the button that sent it from inside the function. How would I do that?
The code runs when a certain action is triggered and looks like this:
var newSubmit = document.createElement('input'); ... newSubmit.onclick = function() { };
I want to be able to access the button that sent it from inside the function. How would I do that?
Last edited by jvvg (Sept. 14, 2013 19:15:11)
- blob8108
-
1000+ posts
Accessing sender in JS anonymous event handlers
Is it a property of the event object passed to the on click handler? Did you try `this`?
- jvvg
-
1000+ posts
Accessing sender in JS anonymous event handlers
I'm kind of dumb sometimes. Is it a property of the event object passed to the on click handler? Did you try `this`?

- Paddle2See
-
1000+ posts
Accessing sender in JS anonymous event handlers
Closed by request of the topic owner.
- Discussion Forums
- » Advanced Topics
-
» Accessing sender in JS anonymous event handlers