Joey Ng'ethe Joey Ng'ethe - 1 month ago 9x
jQuery Question

Maximum call stack size exceeded on trigger click

I really want to do something simple. On click on a certain element, i trigger a click on another element but i get the below error on my console.

Uncaught RangeError: Maximum call stack size exceeded

My code is as below;

$('body').on('click', '.actual-click-element', function(event) {

I wonder why am am getting this error and i don't see how this is recursive. Any ideas?


Surely because .trigger-click-element is descendant of .actual-click-element...

To avoid recursive call, you could use jq triggerHandler():

Events triggered with .triggerHandler() do not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.

$('body').on('click', '.actual-click-element', function(event) { 

Now if $('.trigger-click-element') returns more than one element, you could use: