Summer Sale! All accounts are 50% off this week.

Benko's avatar
Level 6

Passing target parameter to setTimeOut()

This is kind of a noob question, but when I have a function like so:

copyToClipboard = e => {
    // do some more stuff
        e.target.innerText = "Copied to clipboard";

        setTimeout(e => (e.target.innerText = "Copy"), 4000);
    };

How do pass on the e parameter? I've tried to look it up, but to no avail.

Thanks.

0 likes
2 replies
bobbybouwmann's avatar
Level 88

e stands for event here, however it's only available whenever your action works with a callback for certain types. For example on click or onkeypress

element.onkeypress = function(e) {
    // Do something here
};

element.onkeypress = (e) => {
    // Do something here
};

Your copyToClipboard is a custom method so it doesn't understand that and you can't magically get that element.

Normally you would just create a normal method and pass it to there

function copyToClipboard(e) {
    // Do something here 
})
1 like

Please or to participate in this conversation.