javascript anchor code example

Example 1: js get anchor

window.location.hash

Example 2: js get anchor

var url = "www.aaa.com/task1/1.3.html#a_1";
var hash = url.substring(url.indexOf("#")+1);

Example 3: how to create an anchor tag in javascript

//for adding a link through JavaScript 
let anchor=document.createElement("a");
anchor.href="_anylinkthatyouwanttoadd_";
anchor.innerText="Go to the above link";//optional
console.log(anchor)
let to_add=document.getElementById("the-id-of-the-element-where-you-want-to-add")
to_add.appendChild(anchor)