0

Here is my code.

document.getElementById("t-option").addEventListener("click", function () {
    setTimeout(function () {
        myFunction(this);
    }, 1500)
});

I want "this" to return the "t-option". It is a radio button and I want to know each time which one has been called.

Maybe there is a complete alternative way to do this, I don't know.

Andreas
  • 21,535
  • 7
  • 47
  • 56
  • `document.getElementById("t-option").addEventListener("click", function () { setTimeout(function () { myFunction(this); }.bind(this), 1500) });` or `document.getElementById("t-option").addEventListener("click", function () { setTimeout(() => { myFunction(this); }, 1500) });`would also work. – connexo Jan 29 '18 at 14:32

1 Answers1

0

This might help you.

function myFunction(self)
{
    console.log(self);
}

var option = document.getElementById("t-option");
option.addEventListener("click", function(){
  var self = this;
  setTimeout(function() { myFunction(self);}, 1500);
});
<input type="checkbox" id="t-option">
Vignesh Raja
  • 7,927
  • 1
  • 33
  • 42