I’ve read the other posts on this, but I’m still unable to get may page jumping to the top when a tab is clicked. Heres the HTML
<ul class="tabs-nav">
<li class="active"><a href="#tab1"><i class="icon-list-ul"></i> Tab 1</a></li>
<li><a href="#tab2"><i class="icon-map-marker"></i> Tab 2</a></li>
</ul>
<!-- Tabs Content -->
<div class="tabs-container">
<div class="tab-content" id="tab1">Stuff</div>
<div class="tab-content" id="tab2">Stuff</div>
</div>
And here is the js…
(function() {
var $tabsNav = $('.tabs-nav'),
$tabsNavLis = $tabsNav.children('li'),
$tabContent = $('.tab-content');
$tabsNav.each(function() {
var $this = $(this);
$this.next().children('.tab-content').stop(true,true).hide()
.first().show();
$this.children('li').first().addClass('active').stop(true,true).show();
});
$tabsNavLis.on('click', function(e) {
var $this = $(this);
$this.siblings().removeClass('active').end()
.addClass('active');
$this.parent().next().children('.tab-content').stop(true,true).hide()
.siblings( $this.find('a').attr('href') ).fadeIn();
e.preventDefault();
});
})();
Now I’ve tried adding
onclick="return false;"
to the tab href in the html, but that is doing nothing. Any help very much appreciated! Thanks!
its jumping to the top because of this
<a href="#tab1">try
<a href="javascript:void(0);"and use another attribute to identify which div should be opened , you can add anyattribute starting withdata-such asdata-id="#tab1then read that attribute ,or you can just rethink how your HTML is setup,
if you really must keep things the way they are then you can try
then: