Simulating clicks
There may be times when you want to programmatically select a particular tab and show its content. This could happen as the result of some other interaction by the visitor.
We can use the option
method to do this, which is completely analogous with the action of clicking a tab. Alter the final <script>
block in tabs12.html
, so that it appears as follows:
<script> $(document).ready(function($){ $("#myTabs").tabs(); $("#remove").click(function() { var indexTab = parseInt($("#indexNum").val(), 10); var tab = $( "#myTabs" ).find(".ui-tabs-nav li:eq(" + indexTab + ")").remove(); $("#myTabs").tabs("refresh"); }); $("#add").click(function() { $("<li><a href='remoteTab.txt'>New Tab</a></li>").appendTo("#myTabs .ui-tabs-nav"); $("#myTabs").tabs("refresh"); var tabCount = $("#myTabs ul li").length; $("#myTabs").tabs("option", "active", tabCount - 1); }); }); </script>
Save this...