Skip to content

Instantly share code, notes, and snippets.

@linuskmr
Last active December 19, 2022 10:49
Show Gist options
  • Save linuskmr/9582dd4dfa101971f34bceb7e28cf409 to your computer and use it in GitHub Desktop.
Save linuskmr/9582dd4dfa101971f34bceb7e28cf409 to your computer and use it in GitHub Desktop.
Clicking on an abbr opens an alert box showing its title/explanation. This is useful on mobile devices that don't show the title in a tooltip.
// Setup onclick handler for abbr tags. Clicking on an abbr opens an alert box
// showing its title/explanation. This is useful on mobile devices that don't
// show the title in a tooltip.
const abbrs = document.getElementsByTagName("abbr")
const titleSpans = document.querySelectorAll("span[title]")
for (const abbr of [...abbrs, ...titleSpans]) {
abbr.onclick = e => alert(`${e.target.innerText}: ${e.target.title}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment