jQuery Error: Uncaught RangeError: Maximum call stack size exceeded [closed]

1

I have a simple function in jQuery, however it is displaying the error:

  

Uncaught RangeError: Maximum call stack size exceeded

To illustrate, there are 2 or 3 links that I have on the 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;
});
    
asked by anonymous 28.09.2016 / 14:09

2 answers

8

You are being victim of an loop infinity.

See. This is your code.

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

Every time an element with class botchat is clicked, it will be fired. Now look at this part

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

This calls the click event of the element that has the islpronto_link id. 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.

    
28.09.2016 / 14:39
-1

I want to thank you very much for the help, I believe I found a path not 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/>

Thank you again!

    
28.09.2016 / 16:46