Javascript Tab
How do I make an javascript tab?
Javascript based tab without any single line of html. What is a javascript tab? How do you make a javascript tab? This script and codes were developed by Krishna Babu on 11 January 2023, Wednesday.
Javascript Tab - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Javascript Tab</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Javascript Tab - Script Codes CSS Codes
.tab{ margin: 0; padding: 0; list-style: none; } .tab li{ display: inline-block; padding: 10px 20px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-right: 0; border-bottom: 0; } .tab li.active{ background: #fff000; } .tab li:last-child{ border-right: 1px solid #ccc; } .content-holder{ display: block; border: 1px solid #ccc; width: 100%; margin-bottom: 20px; } .content-holder .content{ display: none; padding: 20px; } .content-holder .content.active{ display: block; }
Javascript Tab - Script Codes JS Codes
var array1 = [{tab:"Tab1", content:"Tab 1 content"}, {tab:"Tab2", content:"Tab 2 content"}, {tab:"Tab3", content:"Tab 3 content"}, {tab:"Tab4", content:"Tab 4 content"}];
var array2 = [{tab:"Tab1", content:"Tab 1 content"}, {tab:"Tab2", content:"Tab 2 content"}];
var array3 = [{tab:"Tab1", content:"Tab 1 content"}, {tab:"Tab2", content:"Tab 2 content"}, {tab:"Tab3", content:"Tab 3 content"}];
var array4 = [{tab:"Tab1", content:"Tab 1 content"}, {tab:"Tab2", content:"Tab 2 content"}, {tab:"Tab3", content:"Tab 3 content"}, {tab:"Tab4", content:"Tab 4 content"}, {tab:"Tab5", content:"Tab 5 content"}];
function Tab(str, array){ this.createTab = function(){ var container = document.createElement('div'); var ul = document.createElement('ul'); var holder = document.createElement('div'); for(var i=0; i<array.length; i++){ var li = createTabLi(array[i].tab, i); if(i==0){ li.className = 'active'; }; ul.appendChild(li); var div = createTabContainer(array[i].content, i); if(i==0) { div.classList.add('active'); }; holder.appendChild(div); } ul.className = 'tab'; container.appendChild(ul); holder.className = 'content-holder'; container.id = str; container.appendChild(holder); document.body.appendChild(container); } function createTabLi(text, index) { var li = document.createElement('li'); li.setAttribute('data-tab',('tab-'+(index+1))); li.addEventListener('click', showTab); li.innerHTML = text; return li; }; function createTabContainer(text, index) { var div = document.createElement('div'); div.id = ('tab-'+(index+1)); div.className = 'content'; div.innerHTML = text; return div; } function showTab(e){ var target = e.target; var attr = target.getAttribute('data-tab'); var c = document.getElementById(str).getElementsByClassName('content-holder')[0].children; var d = document.getElementById(str).getElementsByClassName('tab')[0]; for(var i=0; i<c.length; i++){ c[i].classList.remove('active'); d.childNodes[i].classList.remove('active'); if(c[i].id == attr){ c[i].classList.add('active'); } } this.classList.add('active'); }
};
var tab1 = new Tab('tabing1', array1);
tab1.createTab();
var tab2 = new Tab('tabing2', array2);
tab2.createTab();
var tab3 = new Tab('tabing3',array3);
tab3.createTab();
var tab4 = new Tab('tabing4',array4);
tab4.createTab();
Developer | Krishna Babu |
Username | krishnab |
Uploaded | January 11, 2023 |
Rating | 3 |
Size | 2,394 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Simple css3 loader | 1,624 Kb |
Upload Button | 2,535 Kb |
AngularJs Combobox | 2,015 Kb |
Paging | 2,753 Kb |
Wipe slider | 2,370 Kb |
Horizontal Scrolling | 2,825 Kb |
Customize Selector with Google Font | 2,448 Kb |
Bootstrap Carousel | 2,027 Kb |
Page | 1,939 Kb |
Responsive Calendar | 3,174 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Simple Weather App | Cmwebby | 0 Kb |
Eunice A | Ejbronze | 2,203 Kb |
Shape Outside - Polygon | Stacy | 3,954 Kb |
Hover Animation from UNIQLO | Insprd | 3,772 Kb |
Scroll using CSS | Casperovic | 2,159 Kb |
Fullscreen Parallax | Bassta | 3,313 Kb |
Simple Accordion | Wearebold | 3,683 Kb |
Mondrian | Chrisarmstrong | 2,787 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Simple Buttons | Haydenmills | 1,750 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!