// 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'HTMLAnchorElement: search property / notebook
HTMLAnchorElement: search property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let params = new URLSearchParams(queryString);
let q = parseInt(params.get("q"), 10); // returns the number 123