Say I have an element <a href="/foo#bookmark">. I want to reference this element by its hash, which I can do using jQuery. How would I do this only using JavaScript?
Example code:
<a id="foo" href="/foo#bookmark" onclick="exampleFunction(this)">Some text</a>
<script>
/**
* @param {Element} el
*/
function exampleFunction(el) {
let bookmarkHash = el.hash,
$bookmarkElement = jQuery(bookmarkHash);
console.info($bookmarkElement.offset().top);
}
</script>
Here jQuery(bookmarkHash) references the original <a> so I can get the offset of the element. How can I do this in pure JavaScript?
$bookmarkElement = $(el);