Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Uncaught RangeError: Maximum call stack size exceeded

Tags:

The following code (see Fiddle here) throws the stack overflow referred to in the question title. I'm trying to get a box shadow to display around a circular image in a pulse effect. Can anyone point out the recursion, please? I'm very much a Javascript novice and can't see it. Thank you.

HTML

<div id="pulseDiv">        <a href="#" id="advisers-css-image">            <div id="advisersDiv"><img src="http://ubuntuone.com/1djVfYlV62ORxB8gSSA4R4"></div>       </a> </div> 

CSS

.pulse { box-shadow: 0px 0px 4px 4px #AEA79F; } 

Javascript

function fadeIn() {    $('#pulseDiv').find('div.advisersDiv').delay(400).addClass("pulse");    fadeOut(); };  function fadeOut() {    $('#pulseDiv').find('div.advisersDiv').delay(400).removeClass("pulse");    fadeIn(); }; 
like image 906
Clive van Hilten Avatar asked May 22 '13 14:05

Clive van Hilten


People also ask

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

The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. 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.

What does error RangeError maximum call stack size exceeded see JavaScript console for details mean?

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 the maximum call stack size exceeded?

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.


2 Answers

Your calls are made recursively which pushes functions on to the stack infinitely that causes max call stack exceeded error due to recursive behavior. Instead try using setTimeout which is a callback.

Also based on your markup your selector is wrong. it should be #advisersDiv

Demo

function fadeIn() {     $('#pulseDiv').find('div#advisersDiv').delay(400).addClass("pulse");     setTimeout(fadeOut,1); //<-- Provide any delay here };  function fadeOut() {     $('#pulseDiv').find('div#advisersDiv').delay(400).removeClass("pulse");     setTimeout(fadeIn,1);//<-- Provide any delay here }; fadeIn(); 
like image 169
PSL Avatar answered Oct 06 '22 05:10

PSL


your fadeIn() function calls the fadeOut() function, which calls the fadeIn() function again. the recursion is in the JS.

like image 43
Duan Walker Avatar answered Oct 06 '22 04:10

Duan Walker