Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Stop javascript show from jumping to top of page…

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34446
    Brightonmike
    Member

    On this page: http://beta.jetbookingdirect.com/?page_id=128

    I have these little blue buttons that when clicked display some info. Only the first one works – but there is a problem. When you click it, the page jumps to the top. This is going to be annoying if there’s lots.

    Does anyone know how to stop this?

    I know I could use an anchor so it jumps to where the info is, but thats not ideal, I’d rather it didn’t jump at all. My code is below.

        $(document).ready(function(){

    $("#emptybook").click(function(){

    $("#bookempty").slideDown("slow");

    });


    $("#closeemptybook").click(function(){
    $("#bookempty").slideUp("slow");
    });

    });

    #87662
    Brightonmike
    Member

    I figured it out. Use return false.

        $(document).ready(function(){

    $("#emptybook").click(function(){

    $("#bookempty").slideDown("slow");return false

    });

    $("#closeemptybook").click(function(){
    $("#bookempty").slideUp("slow");return false
    });

    });

    Wunderbar!

    #87663
    jamygolden
    Member

    You shouldn’t use return false when it’s not necessary. Use e.preventDefault() instead.

    $(document).ready(function(){

    $("#emptybook").click(function(e){
    $("#bookempty").slideDown("slow");
    e.preventDefault;
    });

    $("#closeemptybook").click(function(e){
    $("#bookempty").slideUp("slow");
    e.preventDefault;
    });

    });
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.