D
D
Dmitry2015-08-17 22:57:59
JavaScript
Dmitry, 2015-08-17 22:57:59

Why does the Maximum call stack size exceeded error occur?

temporarily lies on the page
since the button appears on a hover event, we won’t see it on mobile,
so I decided that when clicking on squares__item , the click was transferred to the button

$('.squares__item').on('click', function() {
    $(this).find('.squares__des__button').click();
  })

but for some reason, the error Maximum call stack size exceeded
actually crashes, what did I do wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Protko, 2015-08-17
Protko @Fesor

Apparently you caused a recursion.

V
Vitaly Inchin ☢, 2015-08-18
@In4in

Read about event bubbling .

$('.squares__item').on('click', function() {
    $(this).find('.squares__des__button').click();
    //Событие всплывает и происходит новый клик по .squares__item
    //А на нем висит вызов клика по .squares__des__button
   //И так бесконечно
  })

Can be used
but why?
Better hang a single handler on .squares__item . The one that was hung on the poor button. The essence will not change, but the error will go away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question