There is a number of bootstrap tabs and each tab has sample table with a big number of "td" elements. We bind a click event on the td's of the active tab. For performance, we want to unbind the click events of the previous tab each time the user changes tabs.
Here's the demo: http://jsfiddle.net/hyTCy/
(the 'shown' event is after all transitions are completed)
$('a[data-toggle="tab"]').on('shown', function (e) {
var newt = $(e.target).attr("href"),
prevt = $(e.relatedTarget).attr("href");
console.log("new tab: " + newt) // activated tab
console.log("prev tab: " + prevt); // previous tab
$(newt + " tbody").on("click", "td", function (e) {
console.log("click");
});
var validate = function () {
console.log("prev click ok");
};
$(prevt + " tbody").off("click", "td", validate);
});
Normally, if you visit the demo and click the tab "profile" and then "home", there should be displayed a message in the console "prev click ok", so that we know the events in the previous tab have been unbinded.
Why isn't function validate working properly?... Thanks!