Jquery Slide problem
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 jum开发者_运维问答ps 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>
$(document).ready(function(){
$("[href='#']").click(function(e){
e.preventDefault();
$("#message_panel").slideToggle("slow");
});
});
$("[href='#']").click(function(e){
e.preventDefault();
$("#message_panel").slideToggle("slow");
});
e.preventDefault() should do the trick
The jumping issue is because you are using '#' as the link. Start using Javascript:void(0)
in those cases instead.
精彩评论