Scroll to Div

I currently have a scroll to DIv Javascript is possible to combine them somehow
to not have so much script. Since I am targeting different Divs?

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#photosinuse, #howtoapply").offset().top
    }, 2000);
});  
                                                                                                                                                                                                                                                                                                                                                                                                                                                    $("#button2").click(function() {
    $('html, body').animate({
        scrollTop: $("#howtoapply").offset().top
    }, 2000);
});

At a guess maybe something like this:

$("#button,#button2").click(function() {
        var destination = "#photosinuse";
				if ($(this).attr('id') === 'button2'){destination = "#howtoapply";}
				$('html, body').animate({
            scrollTop: $(destination).offset().top
        }, 2000);
    });

that worked thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.