What's the best way to detect switching between tabs inside a tabbox
?
In particular, I need to detect when a certain tab is opened, and when the user leaves it (switches to another tab).
I'm using onclick
now but that feels hackish.
Listen for the select
event on the tabpanels
element:
var panels = document.getElementById("tabpanels"); // whatever your ID is
panels.addEventListener("select", function(e) {
var el = e.target;
alert(e.target.tagName); // tabpanels
alert(e.target.selectedPanel) // [object XULElement] (the selected tab)
}, false);