JSFiddle - React, Tailwind, and code Playground

by Dedi Wibisono

HTML

<!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>