How to use jQuery to show/hide divs based on radio button selection?

后端 未结 8 684
暗喜
暗喜 2020-11-30 05:38

I have some radio buttons and I\'d like to have different hidden divs show up based on which radio button is selected. Here\'s what the HTML looks like:

<         


        
8条回答
  •  遥遥无期
    2020-11-30 06:11

    Just hide them before showing them:

    $(document).ready(function(){ 
        $("input[name$='group2']").click(function() {
            var test = $(this).val();
            $("div.desc").hide();
            $("#"+test).show();
        }); 
    });
    

提交回复
热议问题