How to get the URL of an element by that element's CSS selector?

A certain <a> element with dynamic URL has a unique CSS ID.

How could I use this CSS ID to know what is the current URL of this link, with vanilla JavaScript?

1 Like

This worked for me to get the URL by selector:

let editButton = document.querySelector('#myCSSID').href;

I printed it in console this way:


getElementById would also work.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.