Onclick does not call the function

Asked

Viewed 1,043 times

0

Guys I’m wearing webpack and babel to use the new features of ES6, mainly the part of modularization which is working perfectly and I am also using a development server. Turns out for some reason in mine index.html the event onclick does not call any function I specify within it:

<button class="btn btn-primary btn-lg mt-5" href="#" role="button" onclick="apostar()">

The Error message that appears in the Browser console is this:

Uncaught Referenceerror: betting is not defined At Htmlbuttonelement.onclick

I’m using bundle.js usually from webpack.

2 answers

1

I believe the function apostar is defined in a file *.js separate, just as the good practices.

but the same should be minified by webpack, and during this process variables (including functions) are renamed.

What I advise, is that you also apply the good practices in your file HTML and do not bind functions inline, instead, make use of good old addEventListener.

  • In this case, my webpack is generating the 'Bundle.js' in memory... It is not physically generating the file on the hard drive. But I can open the 'Bundle.js' in memory through the Browser console and the betting function is there minificada... I will follow your guidelines !!!!! I really thank you!!!!!!!!! Thanks a lot! !!!!!!!!!!

0

Good morning, as Lucas said, it may be that your call is not taking effect, put it at the bottom of the page.

@Section scripts{

@Scripts.Render("~/JS/Funcao")

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.