There is such an input

<input type="text" class="correctMoney"> 

There is a function for example

  function correctMoney (e){ alert($(e.currentTarget)) } 

how do i register an event like so

 $('.correctMoney').on('click', correctmoney(event, {forDisplay: true, classOfDomElement: 'resOne,resTwo', showPoint: false})); 

just if I prescribe so then I get an error when loading the page

 Cannot read property 'currentTarget' of undefined 

Threat trying to modify github index.html here with

 <input type="text" class="correctMoney" onkeyup="correctmoney(event, {forDisplay: true, classOfDomElement: 'resOne,resTwo', showPoint: false})"> 

on

  <input type="text" class="correctMoney"> <script> $('.correctMoney').on('click', correctmoney(event, {forDisplay: true, classOfDomElement: 'resOne,resTwo', showPoint: false})); </script> 

    1 answer 1

    The code in the attributes is wrapped in an anonymous function.
    So you also need to do this, but obviously:

     function correctMoney(e){ alert($(e.currentTarget)); } $('.correctMoney').on('click', e => correctMoney(e, {forDisplay: true, classOfDomElement: 'resOne,resTwo', showPoint: false})); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="correctMoney"> 

    PS correctMoney and correctmoney are different things.

    • Thanks, I added only e => to the code and it worked, and where can I read about this line? (I do not mean ordinary switch functions, then where did you read that it is possible in such a way to transmit an event to the function ) - Goshka Tarasov
    • @ GoshkaTarasov, I did not understand your request. You can read about arrow functions here: developer.mozilla.org/ru/docs/Web/JavaScript/Reference/ ... Event arguments are always passed as an argument to an event object with useful information about the event. - user207618
    • the first time I see such a string e => somewhere else except for the switch functions, so I ask, where did you read that in this way you can pass an event object to a function? - Goshka Tarasov
    • @GoshkaTarasov, this is the arrow function. e is the event object. Everything according to canon :) - user207618