0

I am playing with native JavaScript and stumbled upon something strange not sure why this is happening. I have plain html button. All I did is, set the onclick="onclick()". When I run it and click on button I see that there's an error in console.

Console:

Uncaught RangeError: Maximum call stack size exceeded

I don't know why this error is coming. I am seeing this for the very first time. Even when I provide definition of onclick then also the error persists. Can anyone this why this is happening?

console.log(window.onclick);//It logs null
<button onclick="onclick()">Hit me
</button>
Hitesh Kumar
  • 3,238
  • 4
  • 37
  • 70

2 Answers2

0

change onclick to something else

<button onclick="clickme()">Hit me
</button>

When you click button it will call your function onclick which will again call onclick event so it a never ending loop.

Mairaj Ahmad
  • 14,068
  • 2
  • 25
  • 40
0

You need to rename onclick() function name. As Its calling itself every time.

Anand Systematix
  • 632
  • 5
  • 15