{"id":7987,"date":"2021-07-02T21:46:09","date_gmt":"2021-07-02T18:46:09","guid":{"rendered":"https:\/\/elzero.org\/?p=7987"},"modified":"2022-09-28T18:03:16","modified_gmt":"2022-09-28T15:03:16","slug":"tutorials-create-tabs","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-create-tabs\/","title":{"rendered":"Create Tabs"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<ul class=\"tabs\">\r\n  <li class=\"active\" data-cont=\".one\">Tab 1<\/li>\r\n  <li data-cont=\".two\">Tab 2<\/li>\r\n  <li data-cont=\".three\">Tab 3<\/li>\r\n<\/ul>\r\n<div class=\"content\">\r\n  <div class=\"one\">Content 1<\/div>\r\n  <div class=\"two\">Content 2<\/div>\r\n  <div class=\"three\">Content 3<\/div>\r\n<\/div>\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-css\">\r\nbody {\r\n  font-family: Arial, Helvetica, sans-serif;\r\n}\r\n.tabs {\r\n  display: flex;\r\n  list-style: none;\r\n  padding: 0;\r\n  margin: 0;\r\n}\r\n.tabs li {\r\n  padding: 10px;\r\n  background-color: #f6f4f4;\r\n  border-right: 1px solid white;\r\n  cursor: pointer;\r\n  transition: 0.2s;\r\n}\r\n.tabs li.active,\r\n.tabs li:hover {\r\n  background-color: #ddd;\r\n}\r\n.content {\r\n  background-color: #ddd;\r\n}\r\n.content > div {\r\n  padding: 20px;\r\n}\r\n.content > div:not(:first-child) {\r\n  display: none;\r\n}\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nlet tabs = document.querySelectorAll(\".tabs li\");\r\nlet tabsArray = Array.from(tabs);\r\nlet divs = document.querySelectorAll(\".content > div\");\r\nlet divsArray = Array.from(divs);\r\n\r\n\/\/ console.log(tabsArray);\r\n\r\ntabsArray.forEach((ele) => {\r\n  ele.addEventListener(\"click\", function (e) {\r\n    \/\/ console.log(ele);\r\n    tabsArray.forEach((ele) => {\r\n      ele.classList.remove(\"active\");\r\n    });\r\n    e.currentTarget.classList.add(\"active\");\r\n    divsArray.forEach((div) => {\r\n      div.style.display = \"none\";\r\n    });\r\n    \/\/ console.log(e.currentTarget.dataset.cont);\r\n    document.querySelector(e.currentTarget.dataset.cont).style.display = \"block\";\r\n  });\r\n});\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-7987","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=7987"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7987\/revisions"}],"predecessor-version":[{"id":7988,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7987\/revisions\/7988"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=7987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=7987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=7987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}