Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 17
    Could you also use $(selector)[0]?
    – RobW
    Commented Mar 17, 2014 at 19:02
  • 19
    RobW, yes you can just use [0], but get(0) protects you against undefined or negative indexes. See the source: james.padolsey.com/jquery/#v=1.10.2&fn=jQuery.fn.get
    – corbacho
    Commented Apr 2, 2014 at 14:16
  • 25
    If you don't want to use jQuery at all, just use document.getElementById('#elementID').scrollIntoView(). No use loading a ~100k library just to select an element and then convert it to regular JavaScript.
    – Gavin
    Commented Jun 23, 2014 at 18:59
  • 79
    @Gavin I'm sure you meant that to be: document.getElementById('elementID').scrollIntoView()
    – Brian
    Commented Sep 18, 2014 at 21:40
  • Would be nice to be able to define an offset ... stackoverflow.com/q/24665602/1066234
    – Avatar
    Commented May 26, 2022 at 15:28