Search code examples
javascriptjqueryjquery-animatejquery-effects

jQuery multiple radio buttons and load html code?


You think is right this way for show HTML code in each click on radio?
What is you propose to animate (effect) appropriate for show and hide html code?
see you example of my codes: http://jsfiddle.net/9LECb/

$('#housing_select input').click(function(){
        var classes =  $(this).attr('id');
        if(classes == 'hotel_select'){
            $('.hotel_apartment_select, .suite_select').hide();
            $('.'+classes).show();
        }
        if(classes == 'hotel_apartment_select'){
            $('.hotel_select, .suite_select').hide();
            $('.'+classes).show();
        }
        if(classes == 'suite_select'){
            $('.hotel_select, .hotel_apartment_select').hide();
            $('.'+classes).show();
        }
    })

With respect


Solution

  • You can remove the if conditions and minimize the code to:

    $('#housing_select input').click(function() {
        var classes = $("." + this.id);
    
        $('.hotel_apartment_select, .suite_select, .hotel_select').not(classes).hide();
        classes.show();
    })
    

    JSFiddle: http://jsfiddle.net/9LECb/2/ Note: You can check jQuery UI Tabs as they acheive a similar effect