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,508
  • 7
  • 40
  • 71
  • 1
    You bind the button's `onclick` with it's `onclick` function. When you click the button, `onclick` calls for itself again and again – Thum Choon Tat Nov 23 '16 at 09:16

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,434
  • 2
  • 26
  • 40
0

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

Anand Systematix
  • 632
  • 5
  • 15