How can I scroll down to a specific block by pressing a button?

  • 0
    I have this button -
    When I click on it, I need to scroll to the block with id = "cost".
    These are not navigation anchors! I've already made the anchors.
    You just need a simple scroll when you press the button and that's it.
    How to do it?
    I can't find the answer to the question anywhere.
    JavaScript Hunter Murillo, Mar 21, 2020

  • 3 Answers
  • 0
    You can via scrollIntoView

  • 0
    If not an anchor, then what is it? / scro ...

    And you can, as in the old days, animate a scroll on jquery, or even on vanilla, but it's more difficult.

    $('a[href^="#"]').on('click', function(event) {

    var target = $( $(this).attr('href') );

    if( target.length ) {
    $('html, body').animate({
    scrollTop: target.offset().top
    }, 500);


  • 0
    Scrolling but not anchor ... Why, why? Have you read about scroll-behavior ?

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!