fetch anchor tag href value in JavaScript

avatar
May 22, 2023 · Snippet · 1 min, 52 words

The below code gives me the full path,

document.getElementById("anchor_tag_id").href; // http://shouts.dev/snippets/anchor-tag-data

and the below code provides the only path,

document.getElementById("anchor_tag_id").getAttribute("href"); // snippets/anchor-tag-data

Comments

No comments yet…