With jQuery UI tabs, how can I run code after a click on a tab?
Asked Answered
C

4

8

With jQuery UI tabs, you can use the select method to run code when a tab is clicked:

$( ".selector" ).tabs({
   select: function(event, ui) { ... }
});

But the code is run before the just clicked tab has been loaded. I need to run code after new tab has been loaded. How can I do this? Thanks for reading.

Chondriosome answered 14/11, 2010 at 3:7 Comment(0)
T
7
$( ".selector" ).tabs({
   load: function(event, ui) { ... }
});

from http://jqueryui.com/demos/tabs/

Theran answered 14/11, 2010 at 3:10 Comment(0)
S
12

API HAS CHANGED. This event is now "activate"/"tasbactivate"; see http://api.jqueryui.com/tabs/#event-activate

----- OLD Answer below -----------

Based on the question it's the tabsshow (not the tabsload) event that is desired...event is triggered when a tab is shown.

Code examples: ( from http://jqueryui.com/demos/tabs/ )

Supply a callback function to handle the show event as an init option.

$( ".selector" ).tabs({
   show: function(event, ui) { ... }
});

Bind to the show event by type: tabsshow.

$( ".selector" ).bind( "tabsshow", function(event, ui) {
  ...
});

The event is useful if you want to set focus on control or similar.

Styracaceous answered 22/12, 2011 at 5:51 Comment(3)
This event is now "activate"/"tasbactivate"; see api.jqueryui.com/tabs/#event-activateEmbalm
agreed on this answer... makes more sense for what the user is asking.Tuyere
I just hate it that there is no event when you click on an active tab. It blocks the click calls but, gives you no event eitherColtin
T
7
$( ".selector" ).tabs({
   load: function(event, ui) { ... }
});

from http://jqueryui.com/demos/tabs/

Theran answered 14/11, 2010 at 3:10 Comment(0)
W
6

looks like you could bind to tabsload or tabsshow:

http://jqueryui.com/demos/tabs/#Events

example

$('#example').bind('tabsshow', function(event, ui) { ... });
Weisler answered 14/11, 2010 at 3:13 Comment(2)
This event is now "activate"/"tasbactivate"; see api.jqueryui.com/tabs/#event-activateEmbalm
To be clear, you wouldn't use the bind() method: $( ".selector" ).tabs({ activate: function( event, ui ) { } });Pals
H
0

HTML

<div id="tabs">
    <ul>
        <li><a href="#job_information_tab">Job Information</a></li>
    </ul>
    <div id="job_information_tab">
        [content]
    </div>
</div>

JS

$('a[href="#job_information_tab"]').on('click', function() {
   alert("Don't tickle me! I am gonna pee!");
});
Handset answered 28/10, 2020 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.