Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<tab>
  <ol class="nav">
    <li><a href="./tab1">tab-1</a></li>
    <li><a href="./tab2">tab-2</a></li>
  </ol>
  <ol class="content">
    <li>content-1</li>
    <li>content-2</li>
  </ol>
</tab>
  
</body>
</html>
 
selectTab()
$('tab').on('click','.nav > li > a',(e)=>{
  
  e.preventDefault()
  
  let a = e.currentTarget
  
  let path = a.getAttribute('href')
  
  window.history.pushState({},'abc',path)
  
  selectTab()
  
})
function selectTab(){
  
  let index = location.pathname.substring(1) || 'tab1'
  index = index.substring(3) - 1 
  console.log(index)
  
  $('tab > .nav > li').eq(index).addClass('active').siblings().removeClass('active')
  
  console.log('111')
  $('tab > .content > li').eq(index).addClass('active').siblings().removeClass('active')
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers