Looking at your other code you probably want to do something like this: Do not invoke the method when assigning the new onclick handler. Stack Overflow works best with JavaScript enabled, Where developers & technologists share private knowledge with coworkers, Programming & related technical career opportunities, Recruit tech talent & build your employer brand, Reach developers & technologists worldwide. How to deal with an advisor that offers you nearly no advising at all?
The JavaScript onclick event is one of the most frequently utilized event types. site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. The onclick attribute is an event attribute that is supported by all browsers. I faced an issue in a case where creating multiple buttons in a loop and assigning a function for onclick for each button in the loop was not working. If you want to make a button onclick, you need to add the onclick event attribute to the