LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Pure JavaScript Based Multi-Tab With Hash DIV Linkable URL

Pure JavaScript Based Multi-Tab With Hash DIV Linkable URL

Pure-JavaScript-Based-Multi-Tab-With-Hash-DIV-Linkable-URL
This tutorial shows how to create a Web page containing JavaScript-driven tabs. Each tab displays a separate chunk of content when clicked — perfect if your page needs to hold a large amount of content.

I find it’s a common desire with “tab” design patterns that there is a way to link to specific tabs. As in, you could give someone a URL and that URL would lead them to that page with the specific desired tab active and displaying the correct content.

The JavaScript and markup are coded in such a way that the page degrades gracefully in browsers that don’t support JavaScript.

This is a simple frontend utility to help the file-upload process on your website. It is written in pure JavaScript, has no dependencies. You can check out the live demo. For the most part, browsers do a good job of handling image uploads. That being said – we find that the ability to show our users a preview of their upload can go a long way in increasing the confidence in their upload.

Features:

  1. MultiTab Widget.
  2. HASH Based Tab URL.
  3. Direct Open Selcted Tab On Page oad Via Hasg URL.
  4. Light Weight.
  5. Pure JavaScrit.
  6. Cross Browser.
  7. Your code will be lightweight because it will have zero dependencies.
  8. Your website will perform better. You won’t need to load external scripts and stylesheets.
  9. You’ll have more control. You will have built the clock to behave exactly the way you want it to (rather than trying to bend a plugin to your will).
Recommended For You:
HTML5 Web SQL Databases: Learn Basics About How To Use?

How To Use Pure JavaScript Multi-Tab With Hash DIV URL?

There are few easy and understandable steps to achieve your desired functionality using pure Vanilla JavaScript that we are gonna share below. Follow each step perfectly.

CSS:

<style type="text/css">
.exeDIRECTtabsDIV {
display: flex;
flex-wrap: wrap;
margin: 20px 0;
background: #FFFFFF;
box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 10%);
-webkit-box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 10%);
-moz-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.1);
-ms-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.1);
-o-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.1);
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
transition: all .5s ease;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-ms-transition: all .5s ease;
-o-transition: all .5s ease;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav {
float: left;
width: 100%;
margin: 0;
padding :0;
list-style-type: none;
border-bottom: 1px solid #ddd;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav > li > a {
float: left;
margin-right: 2px;
line-height: 1.42857143;
padding: 10px;
border-radius: 5px 5px 0 0;
z-index: 1;
order: 1;
display: block;
cursor: pointer;
transition: background ease 0.2s;
border: 1px solid #CCCCCC;
border-bottom: none;
margin: 0 0 -1px 5px;
padding: 5px 10px;
font-size: 14px;
line-height: 1.71428571;
font-weight: 400;
background: #f7fafc;
text-decoration: none;
white-space: nowrap;
color: #ADADAD;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav > li > a:hover {
border-color: #AAA;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav > li.active > a, .exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav > li.active > a:hover, .exeDIRECTtabsDIV .exeDIRECTtabsDIV-nav > li.active > a:focus {
color: #555;
background-color: #fff;
border: 1px solid #ddd;
border-bottom-color: transparent;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-content {
float: left;
width: 100%;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-content > .exeDIRECTtabsDIV-pane {
display: none;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-content > .exeDIRECTtabsDIV-pane.active {
display: block;
width: calc(100% - 40px);
padding: 20px;
border-top: 1px solid #b7b7b7;
overflow-x: scroll;
}
.exeDIRECTtabsDIV .exeDIRECTtabsDIV-content > .active {
display: block;
}
</style>

HTML:

<div class="exeDIRECTtabsDIV">
<ul class="exeDIRECTtabsDIV-nav">
<li class="active"><a href="#tab-1" id="tab1">Tab 1</a></li>
<li class=""><a href="#tab-2" id="tab2">Tab 2</a></li>
<li class=""><a href="#tab-3" id="tab3">Tab 3</a></li>
</ul>
<div class="exeDIRECTtabsDIV-content">
<div id="tab-1" class="exeDIRECTtabsDIV-pane active">
<h3>Feature 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div id="tab-2" class="exeDIRECTtabsDIV-pane">
<h3>Feature 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div id="tab-3" class="exeDIRECTtabsDIV-pane">
<h3>Feature 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
</div>
</div>

JavaScript:

<script type='text/javascript'>
/* Pure Vanilla JavaScript Multi Tab With Anchor Tag Control Using AddressBar URL
--------------------------------------------------------------------------------- */
window.addEventListener("load", function() {
// store tabs variable
var theTabs = document.querySelectorAll("ul.exeDIRECTtabsDIV-nav > li");
for (i = 0; i < theTabs.length; i++) {
theTabs[i].addEventListener("click", theTabClicks)
}
function theTabClicks(tabClickEvent) {
var clickedTab = tabClickEvent.currentTarget;
var tabParent = tabClickEvent.currentTarget.parentNode.parentNode;
var theTabs = tabParent.querySelectorAll("ul.exeDIRECTtabsDIV-nav > li");
for (var i = 0; i < theTabs.length; i++) {
theTabs[i].classList.remove("active");
}
clickedTab.classList.add("active");

//tabClickEvent.preventDefault(); //Stop Adding #ID In Addressbar
var contentPanes = tabParent.querySelectorAll(".exeDIRECTtabsDIV-pane");
for (i = 0; i < contentPanes.length; i++) {
contentPanes[i].classList.remove("active");
}
var anchorReference = tabClickEvent.target;
var activePaneId = anchorReference.getAttribute("href");
var activePane = tabParent.querySelector(activePaneId);
activePane.classList.add("active");
}
// Open Address Bar Anchor Tag Tab Directly
var hash = window.location.hash; //get the hash from url
cleanhash = hash.replace("#", ""); //remove the #
cleanhash = cleanhash.replace("-", "");
document.getElementById(cleanhash).click();
});
</script>

Customization:

No need to customize it. Just copy paste.

Recommended For You:
Simple And Clean JQuery Horizontal Accordion Tabs

Troubleshooting the Errors

Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us or If you have any doubts and problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave your precious feedback in our comment form below. Happy development, See you in the next article.

You Like It, Please Share This Recipe With Your Friends Using...

  

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *