1

I read almost every SO question about

Uncaught RangeError: Maximum call stack size exceeded.

but non worked for me.

My problem is that I'm changing some div text after loading it, which is working with me. However, the console is displaying the Uncaught RangeError error. this is my JS:

<script type="text/javascript">
            $('#report-error').on("DOMNodeInserted DOMCharacterDataModified" ,function(){
                $('#report-error').text("error happened");

            });           
 </script>

and this is my HTML after the jquery had been applied:

<div id="report-error" class="report-div error" 
style="display: block;">error happened
</div>

Any help would be appreciated.

mamdouh alramadan
  • 8,349
  • 6
  • 36
  • 53

1 Answers1

4

The error happens because the DOMNodeInserted event is triggered when you run the jQuery method .text(), since this method inserts a text node into the container.

So in short - the handler will invoke it’s own event...

You could solve it by using one instead of on, but the side effects depends on the rest of your logic.

$('#report-error').one("DOMNodeInserted" ,function(){
    $('#report-error').text("error happened");
});
David Hellsing
  • 106,495
  • 44
  • 176
  • 212