IDs are the simplest and easier selector to write for one key reason: in any properly-written HTML page, every ID should be unique. This is a rule in HTML and although it’s not enforced (the page will still load if the rule is broken), generally sites will abide by it. So in this example:
<a href="https://example.com/another-page" class="link-to-another-page" id="anotherpage">Click me</a>
The ID “anotherpage” should not appear anywhere else in the page, so it’s safe to use as a selector.
Within the RapidSpike script editor, you would select the type “id” and set “anotherpage” to be the selector, like this:
ID’s are great… until they’re not. Unfortunately there are a few potential pitfalls:
The first is that the website you’re using hasn’t followed the rules, and your ID is not unique. One way to test if an element is unique is to use the Inspect view in your browser and to search for the ID in the search box that most browsers include. Note: If you can’t see a search box, try pressing CMD+F (Mac) or CTRL+F (PC).
The second issue you may encounter is that a site may be using dynamic IDs. Some sites generate IDs automatically – for example including product codes, tracking identifiers, version releases, date and time stamps and so on. This might mean that the ID changes often – maybe even on each visit to the site. For this obvious reason, dynamic IDs are useless for writing scripts because the User Journey will break each time the ID changes and the selector no longer matches.
If you suspect the IDs may be automatically generated it’s worth checking if they change by reloading the site and checking again. Generally speaking, if the ID contains a lot of letters and numbers in a long string it is likely a “generated” ID and not worth using.