You could just use CSS without any javascript.
Give your anchor a class:
<a class="anchor" id="top"></a>
You can then position the anchor an offset higher or lower than where it actually appears on the page, by making it a block element and relatively positioning it. -250px will position the anchor up 250px
a.anchor {
display: block;
position: relative;
top: -250px;
visibility: hidden;
}
Related Contents:
- offsetting an html anchor to adjust for fixed header [duplicate]
- Make anchor link go some pixels above where it’s linked to
- CSS- Highlight a div when the id is linked to using an anchor?
- Get div height with plain JavaScript
- How to add `style=display:”block”` to an element using jQuery?
- horizontal scrollbar on top and bottom of table
- Make header and footer files to be included in multiple html pages
- execCommand() is now obsolete, what’s the alternative?
- How do I detect “shift+enter” and generate a new line in Textarea?
- Is it possible to hide the cursor in a webpage using CSS or Javascript?
- How do I clear the content of a div using JavaScript? [closed]
- How to add background-image using ngStyle (angular2)?
- Change :hover CSS properties with JavaScript
- How do you read CSS rule values with JavaScript?
- Using jQuery how to get click coordinates on the target element
- How to change CSS :root color variables in JavaScript
- JavaScript CSS how to add and remove multiple CSS classes to an element
- What is a practical maximum length for HTML id?
- How to silently hide “Image not found” icon when src source image is not found
- Creating a select box with a search option
- How does the data-toggle attribute work? (What’s its API?)
- How to change CSS property using JavaScript
- Best way to do a split pane in HTML [closed]
- How to connect HTML Divs with Lines? [duplicate]
- How to use aria-expanded=”true” to change a css property
- Text-overflow ellipsis on left side
- how to hide blinking cursor in input text?
- How to dynamically create ‘@-Keyframe’ CSS animations?
- How do I make an “else” in an IE HTML conditional?
- How can I scroll a div to be visible in ReactJS?
- JavaScript Loading Screen while page loads
- Access a variable of iframe from parent
- In Javascript, how do I “clear” the back (history -1)?
- Difference between Relative path and absolute path in javascript
- Wrap link around
- What are the cons of using a contentEditable div rather than a textarea?
- How to scroll table’s “tbody” independent of “thead”?
- Is there a way to curve / arc text using CSS3 / Canvas
- Add CSS3 transition expand/collapse
- How to overlay a div (or any element) over a table row (tr)?
- How to get bounding box for div element in jQuery
- jQuery how to get innerWidth but without the padding?
- Change link color of the current page with CSS
- Set the default value in dropdownlist using jQuery
- Change the style of :before and :after pseudo-elements? [duplicate]
- Bootstrap 4 Dropdown Menu not working?
- Draw an arrow between two divs
- Iframe inherit from parent
- How to write inside a DIV box with javascript
- Preloading Google Fonts