Events

onbeforematch

A hidden-until-found subtree is about to be revealed by a find-in-page match or fragment navigation. HTML event-handler content attribute or corresponding event-handler property; the event fires only on relevant targets. The example uses document.getElementById("demo"). Event interface: Event. For the described native event: bubbles: yes; cancelable: no. Use hidden="until-found"; update related UI without preventing the reveal. Example: Click Reveal section in a browser that supports hidden until found. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.

Formal Syntax & Structure

html syntaxhtml
<section onbeforematch="handleEvent(event)">  target.addEventListener("beforematch", event => { /* handle event */ });

Parameters & Attributes

NameTypeDescription
onbeforematchJavaScript handler bodyOptional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute.
eventEventEvent object delivered to the addEventListener callback; event.type is "beforematch". Inspect target, currentTarget, bubbles and cancelable as appropriate.

Working Example

Example Snippethtml
<a href="#demo">Reveal section</a><section id="demo" hidden="until-found">Hidden searchable text</section><p role="status" id="log">Waiting for beforematch</p><script>  const target = document.getElementById("demo");  const log = document.getElementById("log");  target.addEventListener("beforematch", event => {    log.textContent = String(event.type);  });</script>
HTML Reference