How to make avtovyzov function with the passed event?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Hi all. Trying to call a function that I created with the passed argument event and get the error.

$('#button').on('click', myFunc); function myFunc(event) { ..... }; myFunc(); // event is undefined myFunc(event); // event is undefined

How to call her immediately ?

Or is it like this cause ?

function myFunc(event) { ..... }(); // doesn't work.

And now can't use the event handler for the click

$(function myFunc(event) { ...... }());

Now you have each time you call the function to send there event ?

Why event is not necessary to tell here ?

$('#button').on('click', myFunc);

Thank you
by | 11 views

1 Answer

0 like 0 dislike
jQuery.on() registers a listener for the click event. In the function myFunc when you click will be passed the argument – the click event.

Before a click event does not exist.

Can create your object click event and pass it to the function:
var myEvent = { target: document.getElementById('button_id'), // ... a bunch of standard properties }; myFunc(myEvent);

Related questions

110,608 questions
257,187 answers
40,796 users