[Solved] clean repetitive javascript code


It seems that calling $( '.none' ).hide(); twice is unnecessary.

Since this is the same type of functionality, add the same class to each of the elements for the click function. Then you want to match it to the list, one way to do this is through a matching attribute so it can be selected.

$(document).ready(function(){

    // it might be better to set this in your css with display:none
    $('.none').hide();

    $('.b a').click(function(){
        var id = $(this).attr('id');
        var list_new = $('ul.' + id).html();
        $('#list').empty().append(list_new);
        $(this).parents('li').hide();
    });

});

I updated your HTML as well, which you can view in the fiddle, but this is the idea.

https://jsfiddle.net/zma424f8/2/

0

solved clean repetitive javascript code