I know this specific question has been asked before, but I am not getting any results using the bind()
event on the jQuery UI Tabs
plugin.
I just need the index
of the newly selected tab to perform an action when the tab is clicked. bind()
allows me to hook into the select event, but my usual method of getting the currently selected tab does not work. It returns the previously selected tab index, not the new one:
var selectedTab = $("#TabList").tabs().data("selected.tabs");
Here is the code I am attempting to use to get the currently selected tab:
$("#TabList").bind("tabsselect", function(event, ui) { });
When I use this code, the ui object comes back undefined
. From the documentation, this should be the object I'm using to hook into the newly selected index using ui.tab. I have tried this on the initial tabs()
call and also on its own. Am I doing something wrong here?
If you want to know tabindex of current element in HTML, then you should use document. activeElement. tabIndex .
var selectedTab = $("#TabList"). tabs(). data("selected. tabs");
hover(function(event) { if (event. fromElement) { console. log("inactive"); } else { console. log("active"); } });
If you need to get the tab index from outside the context of a tabs event, use this:
function getSelectedTabIndex() { return $("#TabList").tabs('option', 'selected'); }
Update: From version 1.9 'selected' is changed to 'active'
$("#TabList").tabs('option', 'active')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With