The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS jquery passing argument to functions?. Reply To: jquery passing argument to functions?.


I can’t see why this would be any different from vanilla javascript. My best advice would be to start reading here and further.

There is an exception for example when you do something like this: button.addEventListener('click', myFunction);, in that case the argument passed is the event.
It’s jQuery equivalent would be something like this: $('button').on('click', myFunction);
Passing an argument to that function would then be something like this: $('button').on('click', myFunction('test'));.
And if you still want to have the event in your array of arguments you can do something like this: $('button').on('click', function (e) { myFunction(e, 'test') });