#javascript function format

7 messages · Page 1 of 1 (latest)

terse rose
#

I have something saying
document.getElementById("button").addEventListener('click', funcName)

and funcName is supposed to do a post using fetch api following this tutorial
https://www.youtube.com/watch?v=fGYQJAlLD68

In this tutorial they put
document.getElementById("button").addEventListener('click', function (e){

/* stuff i have in funcName*/
}).

When I do it my way, it doesnt work, but when I replace funcName in the event listener with their way, it works. How come? (i'm checking that it works by looking at the console log that they did in the video, when I do it my way there is no log, when I do it their way there is one).

Also are there any other weird things like this which I should know about?

Use JavaScript to collect & submit form data...
👉 Professional JavaScript Course: https://www.udemy.com/course/professional-javascript-course/?referralCode=0C1D5752923168BC87C2
👉 Professional CSS Course: https://www.udemy.com/course/professional-css/?referralCode=4C3C08E82629E6B15752
👉 Email newsletter (get notified of new courses): https://emai...

▶ Play video
clear meadow
#

how did u define the funcName function?

terse rose
#

function funcName(){

#

}

#

also tried

#

async function funcName(){

#

}