I have added some JQuery tabs, every time I click on one of them the ID of the link is appended to the url and it jumps to the url, which is really annoying. I have looked for a few fixes like set time out and stopping the postback but nothing seems to work, does anyone have any ideas?
<script type="text/javascript">
$(document).ready(function () {
$('.moo').click(function (evt) {
// stops from submitting the form
evt.preventDefault();
return false;
});
$("#tabs").tabs();
setTimeout(function () {
if (location.hash) {
window.scrollTo(0, 0);
}
}, 1);
});
</script>
<div id="tabs">
<ul>
<li><a href="#tabs-1" class="moo" onclick="return false;" >Nunc tincidunt</a></li>
<li><a href="#tabs-2" class="moo" onclick="return false;" >Proin dolor</a></li>
</ul>
<div id="tabs-1">
<uc1:PrizeDrawMiniListControl ID="PrizeDrawMiniListControl1" runat="server" />
</div>
<div id="tabs-2">
<uc2:MostViewedControl ID="MostViewedControl1" runat="server" />
</div>
</div>
EDIT:
The link is not posting back, it’s just scrolling
http://jsfiddle.net/3au7K/ its working fine now.
Change your javascript function to this
This little hack will do the trick. There is no harm in it because JQuery tabs don’t need href attribute after getting initialized.