HTML JS

HOW TO GET SET REMOVE HREF IN JAVASCRIPT

<a href="https://code-boxx.com" id="demo">Demo</a>

var link = document.getElementById("demo").href;

GET HREF

01

<a href="#" id="demo">Demo</a> GET ELEMENT var a = document.getElementById("demo");

SET TO URL a.href = "http://site.com";   SET TO JS FUNCTION a.href = "javascript:FUNCTION()";

SET HREF

02

SET TO EMPTY a.href = "";   REMOVE ENTIRELY a.removeAttribute("href");

REMOVE HREF

03

<a href="#" id="demo">Demo</a> GET ELEMENT var a = document.getElementById("demo");