Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<title>Sandbox</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
body { background-color: #000; font: 16px Helvetica, Arial; color: #fff; }
#msg, #desc { margin: 10px 0; }
#tabs { height: 80px; }
</style>
</head>
<body>
  
<div id="tabs">
  <ul></ul>
</div>
<div id="msg">output message</div>
<button id="addtab">Add tab</button>
<button id="getindex">Get selected tab index</button>
<button id="getab2">Select to Second tab</button>
<button id="deltab">Remove first tab</button>
<div id="desc">
Double click on tab to close tab or click remove-first-tab button to close tab<br><br>
Click get-index-button when there's no tab, return 0 but sometimes return -1 (bug?)<br>
Click add-tab-button to create first tab, hit get-index-button, still return -1 (bug?)<br>
After created few tabs then close all tabs, click get-index-button return sometimes -1 sometimes 0<br>
<br>
overall,<br>
while the first tab which index is 0 created, .tabs("option", "selected") return -1 not 0<br>
therefore, double click on the tab would not close the tab since the index is wrong
</div>
</body>
</html>
 
var id = 0;
$(function() {
$('#tabs').tabs({
  tabTemplate: '<li class="tab"><a href="#{href}"><span>#{label}</span></a></li>',
  add: function(event, ui) {
      $("#msg").html('add tab at index: ' + ui.index);
      //console.info(ui);
      //console.info(ui.panel);
      //console.info(ui.panel.id);
      $("#tabs").tabs('select', ui.index);
  }
});
$(".tab").die('dblclick').live("dblclick", function(){
  var index = $('#tabs').tabs('option', 'selected');
  $('#tabs').tabs('remove', index);
  $("#msg").html("remove tab: " + index);
});
$("#getindex").click(function() {
  var index = $("#tabs").tabs("option", "selected");
  $("#msg").html("current index: " + index);
});
$("#addtab").click(function() {
  $("#tabs").tabs("add", "#tabs-" + id, "Tab-" + id);
  id++;
});
$("#getab2").click(function() {
  $('#tabs').tabs('select', 0);
  $("#msg").html("selected second tab");
});
$("#deltab").click(function() {
  $("#tabs").tabs("remove", 0);
  $("#msg").html("removed first tab");
});
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers