Reputation: 263
I have this code and want a panel on my page to slide when a link is clicked.
But the problem is that the page jumps to the top. Is there any way to stop the page from jumping to the top?
$(document).ready(function(){
$("[href='#']").click(function(){
$("#message_panel").slideToggle("slow");
});
});
Here's the code I have somewhere down on the same page.
<a href="#" ><span>more</span></a>
<div id="message_panel" class="nodisplay">
message here.
</div>
Upvotes: 0
Views: 69
Reputation: 17156
The jumping issue is because you are using '#' as the link. Start using Javascript:void(0)
in those cases instead.
Upvotes: 0
Reputation: 1247
$("[href='#']").click(function(e){
e.preventDefault();
$("#message_panel").slideToggle("slow");
});
e.preventDefault() should do the trick
Upvotes: 0
Reputation: 42655
$(document).ready(function(){
$("[href='#']").click(function(e){
e.preventDefault();
$("#message_panel").slideToggle("slow");
});
});
Upvotes: 1