Skip to content

getClickedDocument

Jason Godesky edited this page Aug 4, 2026 · 1 revision

getDroppedDocument is a method that takes an HTML element, finds the data-entry-id on it or its nearest ancestor, looks that ID up in a specified Collection, and returns the document (if found).

Parameters

el: HTMLElement

The HTML element to start from — usually from the target property of a MouseEvent.

collection: foundry.utils.Collection<string, T>

The collection to search in (e.g., game.actors or game.items).

Returns

The document that the clicked item refers to or null if it could not be found.

Examples

import { getClickedDocument } from '@revolutionarygamesco/common-foundryvtt'

addEventListener('click', (event: Event) => {
  const actor = getClickedDocument<foundry.documents.Actor>(event.target, game.actors)
  if (!actor) return
  event.target.innerHTML = actor.name
})

Clone this wiki locally