I have the following code: fiddle
Which works great in websites I create my self and with no JS the tabs act as jump links to the relevant sections. When placed in
Solution JSFiddle:: https://jsfiddle.net/incorelabs/mg6e4ren/74/
Implementing Tabs is really simple, I have modified the HTML for your question a bit. Removed the anchor tags coz they are not needed.
HTML
-
Tab 1
-
Tab 2
-
Tab 3
-
Tab 4
Some content for Tab - 1
HTML De-Mystified
jQuery
$(document).ready(function () {
var previousActiveTabIndex = 0;
$(".tab-switcher").on('click keypress', function (event) {
// event.which === 13 means the "Enter" key is pressed
if ((event.type === "keypress" && event.which === 13) || event.type === "click") {
var tabClicked = $(this).data("tab-index");
if(tabClicked != previousActiveTabIndex) {
$("#allTabsContainer .tab-container").each(function () {
if($(this).data("tab-index") == tabClicked) {
$(".tab-container").hide();
$(this).show();
previousActiveTabIndex = $(this).data("tab-index");
return;
}
});
}
}
});
});
jQuery De-Mystified
If there are doubts or if someone has suggestions, do comment on the post.