kevinmkr kevinmkr - 1 year ago 62
jQuery Question

Setting the active tab of an extended jQuery tab widget from within the widget

I've seen several examples of how to set the active tab programmatically from outside of the widget. However, I've extended the tab widget and cannot seem to set the active tab programmatically from within the widget. I've created a small test case to demonstrate.


$.widget( "custom.extendedTabs", $.ui.tabs, {
_create: function() {
var self=this;
return this._super();



<div id="tabs1" class="tabs">
<li><a href="#tabs1_1">HEY1!</a></li>
<li><a href="#tabs1_2">HEY2!</a></li>
<li><a href="#tabs1_3">HEY3!</a></li>
<li><a href="#tabs1_4">HEY4!</a></li>
<div id="tabs1_1">
<p>Content 1</p>
<div id="tabs1_2">
<p>Content 2</p>
<div id="tabs1_3">
<p>Content 3</p>
<div id="tabs1_4">
<p>Content 4</p>


To automatically set the active tab to the 4th one (index 3) on mouseover of the tab widget.


In this demo, the "active" option is successfully being set right after initialization (to index 1) and the focus jumps to the 2nd tab as expected. However, on mouseover, even though the active option is being set successfully to 3 (as verified by the logging), the tab does NOT jump to the 4th tab as expected.

I've found a workaround by simply using the
method of the tab that I want selected. However, that shouldn't be required -- this functionality should work directly within the widget. I'm just missing something. Other options work just fine within the widget. For example, I could call
within the mouseover and it will affect the change as expected.

Any ideas?

Answer Source

Found the solution!

You can call _setOptions() from within the extended widget.

For me, the specific code is:


But, in general, the solution is:

this._setOption("active", <zero-based index of tab to activate>);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download