Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can retrieve the URL from an ahref element using Javascript with the following code:

var link = document.getElementById('my-link'); // Replace 'my-link' with the ID of your ahref element
var url = link.href;
console.log(url); // Output the URL to the console

Alternatively, you can use the getAttribute method to retrieve the href attribute of the ahref element:

var link = document.getElementById('my-link');
var url = link.getAttribute('href');
console.log(url);