Last active
May 25, 2017 05:45
-
-
Save startswithaj/6773174 to your computer and use it in GitHub Desktop.
Bookmarklet for generating link with anchor to selected (highlighted) text by finding the nearest element with an ID by traversing up the dom tree until one is found. Allows you to send links to URL's with a rough anchor to a point on a page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:z = function(x){ return x != null ? x.id != "" && x.id != null ? x.id : z(x.previousElementSibling || x.parentElement) : null}; window.prompt((y=z(window.getSelection().focusNode.parentElement)) != null ? "Copy the below link with " + y + " anchor" : "Cound not find anchor id",y != null ? window.location.href+"#"+y : ""); void(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment