Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded

People also ask

How do I fix uncaught RangeError maximum call stack size exceeded?

The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created. Another option is to use a tracer debugger to keep track of the program's state and find the function that's causing the error.

How do I fix maximum call stack size exceeded see JavaScript console for details?

The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.

What is maximum call stack size exceeded error?

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit. This is almost always because of a recursive function with a base case that isn't being met.

What is uncaught range error?

The Uncaught RangeError is caused when the browser's hardcoded stack size is exceeded and the memory is exhausted. So, always ensure that the recursive function has a base condition that can stop its execution.


As "there are tens of thousands of cells in the page" binding the click-event to every single cell will cause a terrible performance problem. There's a better way to do this, that is binding a click event to the body & then finding out if the cell element was the target of the click. Like this:

$('body').click(function(e){
       var Elem = e.target;
       if (Elem.nodeName=='td'){
           //.... your business goes here....
           // remember to replace $(this) with $(Elem)
       }
})

This method will not only do your task with native "td" tag but also with later appended "td". I think you'll be interested in this article about event binding & delegate


Or you can simply use the ".on()" method of jQuery with the same effect:

$('body').on('click', 'td', function(){
        ...
});

You can also get this error when you have an infinite loop. Make sure that you don't have any unending, recursive self references.


Mine was more of a mistake, what happened was loop click(i guess) basically by clicking on the login the parent was also clicked which ended up causing Maximum call stack size exceeded.

$('.clickhere').click(function(){
   $('.login').click();
});

<li class="clickhere">
  <a href="#" class="login">login</a>
</li>

This problem happened with me when I used jQUery Fancybox inside a website with many others jQuery plugins. When I used the LightBox (site here) instead of Fancybox, the problem is gone.


U can use

  $(document).on('click','p.class',function(e){
   e.preventDefault();
      //Code 
   });