Skip to content

Instantly share code, notes, and snippets.

followPreviousID

Moves backward and upward in the DOM to find the closest node with an ID attribute (i.e. one which can be targeted in the URL fragment). If it finds one, updates the document URL to include that fragment.

The main function is parameterized to allow the maximum search depth to be limited.