1

I am using jQuery UI Tabs, and I am trying to call the destroy method prior to running the tabs, but I am not sure how to check if it has been initialized first. I want to avoid an error stating that I can't call a method before initialize.

Here is my sample code:

// destroy first
$( '.tabs' ).tabs( 'destroy' ); // throws error if not initialized first

$( '.tabs' ).tabs();

I need to destroy first because these tabs are dynamically generated by the user (the user can add more tabs). Once the tabs are added by the user, I need to run tabs() again, but I can't run it twice as it causes issues. Therefore I need to destroy everything first and re-run it.

snumpy
  • 2,808
  • 6
  • 24
  • 39

1 Answers1

5

You can use refresh (you don't need to destroy and re-initialize the tabs)

$( ".tabs" ).tabs( "refresh" );

Process any tabs that were added or removed directly in the DOM and recompute the height of the tab panels

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • Thanks for this however I still need a way to check if it is initialized first because my application is quite complicated and has multiple levels of tabs. Not just one so when I run "refresh", it will still give me the not initialized error. –  May 20 '13 at 18:10
  • I spent an hour with this issue of using ajax to rerender portions of page, which used jquery tabs and this answer right here is exactly what works. – JohnMerlino Dec 06 '13 at 23:10