summaryrefslogtreecommitdiffstats
path: root/tabs/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'tabs/index.html')
-rw-r--r--tabs/index.html59
1 files changed, 59 insertions, 0 deletions
diff --git a/tabs/index.html b/tabs/index.html
new file mode 100644
index 0000000..e50728b
--- /dev/null
+++ b/tabs/index.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ <title>Document</title>
+</head>
+
+<body>
+ <ul class="tabs">
+ <li class="tab-button" data-tab="1">ONE</li>
+ <li class="tab-button" data-tab="2">TWO</li>
+ <li class="tab-button" data-tab="3">THREE</li>
+ </ul>
+
+
+ <main>
+ <div class="tab-content-container" data-tab="1">
+ <h1>ONE</h1>
+ </div>
+ <div class="tab-content-container" data-tab="2">
+ <h1>TWO</h1>
+ </div>
+ <div class="tab-content-container" data-tab="3">
+ <h1>THREE</h1>
+ </div>
+ </main>
+
+ <script>
+ document.querySelectorAll(".tab-content-container[data-tab]").forEach(contentContainer => {
+ contentContainer.style.display = "none";
+ });
+
+ document.querySelectorAll(".tab-button[data-tab]").forEach(button => {
+ button.addEventListener("click", handleButtonClick);
+ });
+
+ function handleButtonClick(element) {
+ if (element.originalTarget.dataset.tab) {
+ document.querySelectorAll(".tab-button[data-tab]").forEach(b => {
+ if (b.dataset.tab === element.originalTarget.dataset.tab)
+ b.classList.add("active");
+ else
+ b.classList.remove("active");
+ });
+ document.querySelectorAll(".tab-content-container[data-tab]").forEach(c => {
+ if (c.dataset.tab === element.originalTarget.dataset.tab)
+ c.style.display = "";
+ else
+ c.style.display = "none";
+ });
+ }
+ }
+ </script>
+</body>
+
+</html> \ No newline at end of file