Avoid window jump to top when clicking #-links

后端 未结 12 1163
礼貌的吻别
礼貌的吻别 2020-11-27 21:32

I\'ve got a page with some questions and answers, the answers are collapsed by default. When they click the question I expand the hidden answer-div. The problem is that when

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 22:17

    Inside your function of:

    And I've used jQuery and .click as event-listener.
    

    Will look something like:

    $("#myID").click(function(){});
    

    Change this to (don't forget the param e inside function(e):

    $("#myID").click(function(e){
        e.preventDefault();
    });
    

提交回复
热议问题