Calling a function with params onclick

I'm trying to call a function with a param. As i have it now the function gets called on load, how can i make it wait for the user to click and still have my param?
deletePostBtn.addEventListener("click", deletePost(baseURL))
deletePostBtn.addEventListener("click", deletePost(baseURL))
3 Replies
13eck
13eck3y ago
You need to use an arrow function:
deletePostBtn.addEventListener("click", () => deletePost(baseURL))
deletePostBtn.addEventListener("click", () => deletePost(baseURL))
JS (and most other languages) invoke a function when () are included, so you're invoking a function they returns another function which is what's run when the button is clicked
Jon
Jon3y ago
Thanks!
b1mind
b1mind3y ago
This is a similar issue you had the other day, I had mentioned all this to you. I would spend some time with it make sure you understand what's happening.
Want results from more Discord servers?
Add your server