Scroll back to the top of scrollable div

后端 未结 15 1276
独厮守ぢ
独厮守ぢ 2020-12-07 14:02
#containerDiv          


        
15条回答
  •  时光说笑
    2020-12-07 14:17

    When getting element by class name, don't forget the return value is an array; Hence this code:

    document.getElementByClassName("dropdown-menu").scrollTop = 0
    

    Would not work. Use code below instead.

    document.getElementByClassName("dropdown-menu")[0].scrollTop = 0
    

    I figured other people might encounter a similar problem as I did; so this should do the trick.

提交回复
热议问题