Anchors for tabs?

The site has tabs.
Standard when you open the website active the first tab. How can that be when you enter links, such as for example website.ru/#link2 to open a website with active the second tab?
June 3rd 19 at 18:54
2 answers
June 3rd 19 at 18:56
document.addEventListener("DOMContentLoaded", function(event) {
 let tab = document.querySelector(location.hash)
 if (tab) {
tab.classList.add('active')
}
});
I guess I had to write how the tabs function) There is an inactive overflow: hidden and display: none - London_Kuphal commented on June 3rd 19 at 18:59
probably you can instead of classList.add('active') to change your display.
Well, or tweak css'ku. - Austen.Thompson53 commented on June 3rd 19 at 19:02
June 3rd 19 at 18:58


 <style type="text/css">
body{
 margin: 0;
 padding: 0;
}
.main{
 width: 960px;
 margin: 10px auto 0 auto;
 background: white;
 padding: 30px;
 border: 1px solid #adaa9f;
}
 ul, div{
 margin-bottom: 10px;
 } 
.main>div{
 padding: 10px;
 border: 1px solid #eaeaea;
 display: none;
}
 .main div:target{
 display: block; 
}
</style>


 <div class="main">
the <ul>
 the <li><a href="#id1">section 1</a></li>
 the <li><a href="#id2">2</a></li>
 the <li><a href="#id3">box 3</a></li>
 the <li><a href="#id4">Unit 4</a></li>
</ul>
 <div id="id1">Text 1</div> 
 <div id="id2">Text 2</div> 
 <div id="id3">Text 3</div> 
 <div id="id4">Text 4</div>
</div>

When you enter in the address bar links to the anchor will not in fact need the active tab? - London_Kuphal commented on June 3rd 19 at 19:01
no - Austen.Thompson53 commented on June 3rd 19 at 19:04

Find more questions by tags JavaScriptHTML