Linking to specific text on page
Menu Scroll to Text in URL
 

Scroll to Text in URL

When you want to position a visitor on a particular place on a page that relates to text that is relevant to the originating page, then a special construct of a URL will allow this. The code that does this is a little more complex that the code fragment and involves adding an event handler to the dialog box (green text).

I came across this when I was looking at lumberjack stuff.

The clicking on the code fragment below will demonstrate this.

The #:~:text= does the business

href="lumberjack.html#:~:text=second%20aldi%20gardenline"

As does the first link below.

Other options

:target - :target is a CSS Pseudo Class. other such Pseudo Classes are :hover, active, :link etc as related to hyperlinks.

The link below for All Pseudo Classes takes you to the W3C page spcifically about these classes.

Adding the event handller - "clickable text" - or adding an eventListener()

This is explained on another page.

Top

Links

Top

References: -

  • 1 - Stackoverflow - https:// stackoverflow.com/ questions/62161819/ what-exactly-is-the-text -location-hash-in-an-url
  • 2 - The GitHub page - https://github.com/WICG/scroll-to-text-fragment#target
  • 3 - All CSS Pseudo Classes - https://www.w3schools.com/css/css_pseudo_classes.asp#:~:text=All%20CSS%20Pseudo%20Classes - this link is actually an example of Scroll to text

Site design by Tempusfugit Web Design -