Hello I am new to programming so please excuse my ignorance.
I have several elements that when clicked use the ScrollTop jQuery function to scroll to a specified point (in another bootstrap nav-tab). I have about 20 different elements that when clicked do this. I have resorted to writing 20 different functions that look similar to the one below. I'm sure there must be a way to store these pairs and have a single ScrollTop function that calls upon those pairs.
$('#element').click(function(e) {
e.preventDefault();
var target = $('#element2').closest('.tab-pane').attr('id');
showTab(target);
setTimeout(function() {
$('html, body, nav').animate({
scrollTop: $("#element2").offset().top -100
}, 500);
}, 500);
});
So my js file has twenty or so of this function, where "#element" and "#element2" are subbed with "#alpha" "#alpha2", "#beta" "#beta2", etc...
Should I be using an array? a class? Thanks for you time.