DOM Interfaces

HTMLAnchorElement

Represents an anchor and exposes parsed URL components, target, download and relationship information. The href property resolves a valid relative URL against the document base; getAttribute('href') preserves the authored attribute. Example result: #intro.

Formal Syntax & Structure

html syntaxhtml
const element = document.getElementById('demo'); // HTMLAnchorElement

Return Value

HTMLAnchorElement

An existing HTML DOM object associated with the a element in this example; this interface is a type, not a function return contract.

Working Example

Example Snippethtml
<a id="demo" href="https://example.com/docs#intro">Read</a><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.hash);</script>
HTML Reference