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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With