dmce
dmce

Reputation: 222

jQuery Tabs - Binding to the tabscreate event

I have almost created a plugin for jQuery UI tabs that gives me next and previous buttons. However, I cannot bind to the tabscreate event to apply some logic for the first tab that is shown.

Ive noticed this inside and outside my plugin (jQuery on the page).

After doing $('#tabs').tabs();

This works

$(tabsSelector).bind("tabsshow", function (event, ui) {
  alert("On Tab Show");
});

This doesnt

$(tabsSelector).bind("tabscreate", function (event, ui) {
  alert("On Tabs Creation");
});

Is it purely because the tabs were created previously and if so how can I add to the create event via a plugin?

Upvotes: 0

Views: 2334

Answers (2)

gor
gor

Reputation: 11658

I think you just can use method length to query tabs count. It is sufficient to make navigation with select method.

If you realy need tabscreate event, wrap calling tabs() method within your plugin, and pass you event handler there. Something like this:

function CustomTabs(selector){
    $( selector ).tabs({
       create: function(event, ui) { /* put your code here */ }
    });
}

Upvotes: 2

Wolfgang
Wolfgang

Reputation: 515

The easist way is not to use your method. Use "$(...).tabs({create: function(event,ui) {your code here} })" will work, but please keep in mind that the "create" event is called (don't know why) AFTER the "show" event (if you use it). Also keep in mind that the "ui" (specially the ui.panel) is NOT AVAILABLE.

Hope it helps :-)

Upvotes: 0

Related Questions