1

I am trying to get the anchor tag from an anchor element link in the page eg

<a href="/page#reviews"> 

Is it possible to access the href so I can isolate #reviews and use it elsewhere in my Tritum script?

Thanks!

naryasece
  • 101
  • 1

1 Answers1

4

Yes, it's possible, using a two step process.

First, you can grab the value of the href attribute using the fetch() function.

Then, working on the isolated string, you can use regular expressions to replace all the characters that occur in front of the hash/pound sign (#) with a blank.

Here's an example using the Tritium Tester: http://tester.tritium.io/52503bcbe166ca7affa4944d90aae39808c8cd8e.

Note: This assumes that everything after the first # sign in the href attribute is what you're looking for.

Zkoh
  • 2,932
  • 3
  • 18
  • 14