MathMLAnchorElement: search property

The search property of the MathMLAnchorElement interface is a search string, also called a query string, that is a string containing a "?" followed by the parameters of the <a> element's href. If the URL does not have a search query, this property contains an empty string, "".

This property can be set to change the query string of the URL. When setting, a single "?" prefix is added to the provided value, if not already present. Setting it to "" removes the query string.

The query is percent-encoded when setting but not percent-decoded when reading.

Modern browsers provide URLSearchParams and URL.searchParams to make it easy to parse out the parameters from the query string.

See URL.search for more information.

Value

A string.

Examples

Basic usage

Given this HTML:

html
<a id="myAnchor" href="https://example.com/subsection?q=123"> ... </a>

you can get the search string of the anchor like this:

js
const mathAnchor = document.getElementById("myAnchor");
mathAnchor.search; // returns '?q=123'

Specifications

Specification
HTML
# dom-hyperlink-search

Browser compatibility

See also

  • The MathML <a> element