Scroll to DIV by ID without jQuery

Use scrollIntoView instead of jQuery animate.

December 16, 2022

There is the method scrollIntoView which is compatible with all modern browser

document.getElementById("scrollhere").scrollIntoView(
   {behaviour:'smooth',
    block:'start'
);

So there is no need to still use this jQuery snippet:

$('html,body').animate({
	scrollTop: $("#scrollhere").offset().top
},'slow');

Behaviour works also with scrollTo.

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “Scroll to DIV by ID without jQuery”

Leave a Reply

Your email address will not be published. Required fields are marked with an *

Recommended

Modify list counter in :before pseudo class with jQuery using start attribute

Suppose you have two ordered list ol tags, and the second one has a start attribute. You also have in…

April 20, 2016

How to write a text description into html input type password

Sometime designers put form labels and instrucions into html inputs. One of the common uses is for login boxes when…

March 10, 2010

Mini gallery/slideshow with PHP and JQuery

Sometimes I’ve had to quickly put in a page a simple slideshow, the first times I’ve searched a lot around…

December 13, 2009

Set “write here” on input type text?

If you are using JQuery framework and you want to set up the default value of some text box in…

November 17, 2009

React links

Collection of links and notes while approaching React.js, next.js and related topics.

December 14, 2022

Add Internet Explorer class to body to detect old browser

When you have clients that still uses an old browser, you need to handle it. This javascript function detects the…

February 27, 2017