Saturday, April 13, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  171] [ 7]  / answers: 1 / hits: 7818  / 8 Years ago, mon, may 2, 2016, 12:00:00

i need help about loading tab content when page is loaded. My example work good but default tab load content only when i click on him. That content is not loaded automatically when page is loaded is empty.



Check:
Fiddle example



Like on example u will see you



<ul class=nav nav-tabs tabs-up id=friends>
<li><a href=/gh/gist/response.html/3843293/ data-target=#contacts class=media_node active span id=contacts_tab data-toggle=tabajax rel=tooltip> Contacts </a></li>
<li><a href=/gh/gist/response.html/3843301/ data-target=#friends_list class=media_node span id=friends_list_tab data-toggle=tabajax rel=tooltip> Friends list</a></li>
<li><a href=/gh/gist/response.html/3843306/ data-target=#awaiting_request class=media_node span id=awaiting_request_tab data-toggle=tabajax rel=tooltip>Awaiting request</a></li>
</ul>
<div class=tab-content>
<div class=tab-pane active id=contacts>
</div>
<div class=tab-pane id=friends_list>
</div>
<div class=tab-pane urlbox span8 id=awaiting_request>
</div>
</div>


And js:



$('[data-toggle=tabajax]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
targ = $this.attr('data-target');

$.get(loadurl, function(data) {
$(targ).html(data);
});

$this.tab('show');
return false;
});

More From » jquery

 Answers
2

Place this at the very end of your script:



$(document).ready(function(){
$('[data-toggle=tabajax]:first').click();
});

[#29033] Saturday, April 30, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaleelh

Total Points: 661
Total Questions: 125
Total Answers: 103

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
;