Question

I've got this code copied and pasted multiple times with different menu-item IDs. Is there a way to simplify it and/or toggle one container at a time? Thank You

$('#menu-item-1 a, #TH').click(function () {    

var $container = $('#boxes');

    setTimeout(function(){ $container.masonry() }, 400);

var collapse_content_selector = $(this).attr('href');


var toggle_switch = $(this);
$(collapse_content_selector).toggle(function () {
    if ($(this).css('display') == 'none') {

    } else {

    }
});    
});

$('#menu-item-2 a, #FM').click(function () {

var $container = $('#boxes');

    setTimeout(function(){ $container.masonry() }, 400);

var collapse_content_selector = $(this).attr('href');

var toggle_switch = $(this);
$(collapse_content_selector).toggle(function () {
    if ($(this).css('display') == 'none') {

    } else {

    }
});
});
Was it helpful?

Solution

$('.ClassOfClickableObjects').click(function () {  

    var $container = $('#boxes');
    setTimeout(function(){ $container.masonry() }, 400);
    var collapse_content_selector = $(this).attr('href');
    var toggle_switch = $(this);

    $(collapse_content_selector).toggle(function () {
        if ($(this).css('display') == 'none') {

        } else {

        }
    });    
});

Is what Blazemonger is suggesting...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top