MDN self-hosted library · e01.org

HTMLAnchorElement: href property

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

js
const anchor = document.createElement("a");
console.log(anchor.href); // ""
js
anchor.href = "";
console.log(anchor.href); // "https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/href"
js
anchor.href = "../../..";
console.log(anchor.href); // "https://developer.mozilla.org/en-US/docs/"
js
console.log(anchor.getAttribute("href")); // "../../.."
js
anchor.href = "https://example.com/path";
console.log(anchor.href); // "https://example.com/path"
js
anchor.href = "https://";
console.log(anchor.href); // "https://"