Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery too much recursion

Im trying to select a radio box when I click an LI. But i get the error "to much recursion".

Code is:

$('li').click( function(){      $('li.selected').removeClass('selected');      $(this).addClass('selected');      $(this).children("input[type=radio]").click(); }); 

This is using jQuery 1.4.2 and UI 1.7.2.

like image 948
Kevin Prince Avatar asked Feb 23 '10 17:02

Kevin Prince


People also ask

How do I fix too much recursion error?

This causes the function to call itself, again and again, making it infinitely recursive. This issue also appears if the same variable is used in the getter. To avoid this problem, make sure that the property being assigned to inside the setter function is different from the one that initially triggered the setter.

What is recursive JavaScript?

Recursion is a process of calling itself. A function that calls itself is called a recursive function. The syntax for recursive function is: function recurse() { // function code recurse(); // function code } recurse(); Here, the recurse() function is a recursive function.


1 Answers

when you .click() the child input, the event bubbles up and re-triggers the li's click(). You need to add a .click() to the input and do event.preventBubble=true; in it, or else just set the checked property instead of click()ing it.

like image 57
MightyE Avatar answered Nov 03 '22 08:11

MightyE