JQuery error: Uncaught RangeError: Maximum Call stack size exceeded [closed]

Closed. this question is out of scope and is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 4 years ago .

improve this question

I have a simple function in jQuery, but it is showing the error:

Uncaught RangeError: Maximum call stack size exceeded

For example, are 2 or 3 links I have on page

<a id="islpronto_link" href="javascript:void(0)" class="bot botchat">Fale Conosco</a>

What is causing this error?

Below my code:

$('.botchat').click(function(){
    $('#islpronto_link').click(); 
    return;
});
Author: LINQ, 2016-09-28

2 answers

You are falling victim to an infinite loop.

See. This is your code.

$('.botchat').click(function(){
    $('#islpronto_link').click(); 
    return;
});

Every time an element with the Class botchat if clicked, it will be fired. Now look at this part

$('#islpronto_link').click(); 

This calls the event click of the element that has the Id islpronto_link. This causes your code to run again, and again, and again...

In practice, this is the same thing as doing

function funcao(){
    funcao();    
}

Notice that the code has no escape, the function always calls itself, infinitely.

 14
Author: LINQ, 2016-09-28 12:44:28

Guys I want to thank strongly for the help, I believe I found a way not too far from what I had previously thought. follows an example code

<head>
   <script   src="https://code.jquery.com/jquery-2.2.4.min.js"   integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>


    <meta charset="UTF-8">
    <script>
        $(function(){
            $(".bot").click(function(){

                $("#islpronto_link").click();
            });

        });

    </script>

    <title>teste</title>
</head>
<body>


<input type="button" class="bot" value="click">

<br/><br/>  
<a id="islpronto_link" class="" href="javascript:void(0)">   teste  </a>
<br/>
<a id="islpronto_link" class="" href="javascript:void(0)">   teste  </a>
<br/>   
<a id="islpronto_link" class="" href="javascript:void(0)">   teste  </a>
<br/>

Again thank you very much!

 -1
Author: Celso Andre, 2016-09-29 00:29:07