<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hahaha</title>
</head>
<body>
<ul>
<li><a href="javascript:rudrSwitchTab('tb_1', 'content_1');" id="tb_1" class="tabmenu active">Tab 1</a></li>
<li><a href="javascript:rudrSwitchTab('tb_2', 'content_2');" id="tb_2" class="tabmenu">Tab 2</a></li>
</ul>
<div id="content_1" class="tabcontent">
Content of the first tab.
</div>
<div id="content_2" class="tabcontent" style="display:none;">
Content of the second tab.
</div>
<script>
function rudrSwitchTab(rudr_tab_id, rudr_tab_content) {
// first of all we get all tab content blocks (I think the best way to get them by class names)
var x = document.getElementsByClassName("tabcontent");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = 'none'; // hide all tab content
}
document.getElementById(rudr_tab_content).style.display = 'block'; // display the content of the tab we need
// now we get all tab menu items by class names (use the next code only if you need to highlight current tab)
var x = document.getElementsByClassName("tabmenu");
var i;
for (i = 0; i < x.length; i++) {
x[i].className = 'tabmenu';
}
document.getElementById(rudr_tab_id).className = 'tabmenu active';
}
</script>
</body>
</html>
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.