jQuery 1.7.1, jQuery UI tabs. I have the following HTML representing tabs,
<div id="tabs">
<ul>
<li><a href="t1" title="content">Gallery</a></li>
<li><a href="t2" title="content">Polls</a></li>
<li><a href="t3" title="content">Events</a></li>
</ul>
<div id="content"></div>
</div>
I need to show an indicator in the 'content' div container when I click or select the tab. I tried the following,
HTML
<div id="content"><img id="ind" src="images/indicator.gif"
alt="Loading..." style="display:none"/></div>
JavaScript
$.ajaxSetup({
cache:false,
beforeSend: function() {
$('#ind').show()
},
complete: function(){
$('#ind').hide()
},
success: function() {}
});
This is working with the following tab select code, which I execute to select a default tab when the page loads,
var $tabs = $('#tabs').tabs();
$tabs.tabs('select', 1);
But whenever i click on the tab, indicator is not displaying. Any idea why?
The jQuery UI Tabs widget has a specific event called beforeLoad for that.
If you look at the official jQuery UI demo for Ajax you will see how that event is used for handling errors. And it's also useful for setting content inside the tabs while loading.
Here is the working code snippet (there is just 1 important line in JS and 3 lines in HTML):
Notice that the loading indicator is in the HTML inside a hidden
<div>
and it's copied inside the tab content while loading (which will be automatically replaced as soon as tab is loaded).You haven't call any ajax in tab selection.
if you are calling tab content by ajax that indicator will display.
I have test this with small example, added below.
New Code with extra JQuery Plugin
This isn't an answer to your specific question but I used the following to achieve a similar result: