MDN self-hosted library · e01.org

HTMLAnchorElement: search property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
// An <a id="myAnchor" href="/en-US/docs/HTMLAnchorElement?q=123"> element is in the document
const anchor = document.getElementById("myAnchor");
anchor.search; // returns '?q=123'
js
let params = new URLSearchParams(queryString);
let q = parseInt(params.get("q"), 10); // returns the number 123