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

后端 未结 8 691
暗喜
暗喜 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:05

    The simple jquery source for the same -

    $("input:radio[name='group1']").click(function() {      
        $('.desc').hide();
        $('#' + $("input:radio[name='group1']:checked").val()).show();
    });
    

    In order to make it little more appropriate just add checked to first option --

    remove .desc class from styling and modify divs like --

    lorem ipsum dolor

    it will really look good any-ways.

提交回复
热议问题