When you click on li, I want the input radio to be pressed.
However, I get an error from the conole log:
Uncaught RangeError: Maximum call stack size exceeded
How to fix it?
Here's the html code:
<ul class="Method"> <li class="shipping_today active"> <label> Label 1 </label> <input value="shipping_today" name="shipping" type="radio" /> </li> <li class="shipping_next_month"> <label> Label 2 </label> <input value="shipping_next_month" name="shipping" type="radio" /> </li> </ul>
Jquery:
$(".Method li").click(function() { var thisLi = $(this); var radio = $(this).find("input:radio"); if (radio.val() == "shipping_today") { $(".Method li").eq(1).removeClass("active"); $(this).addClass("active"); } if (radio.val() == "shipping_next_month") { $(".Method li").eq(-2).removeClass("active"); $(this).addClass("active"); } radio.click();
Is my jQuery code good? what can be improved?
thanks.
source share