'HTML <a> href that points to another <a> href

I have a hidden <a> tag with some id. It renders by script, so I don't have access to it. And I have my own <a> which is visible to user. I want to when user clicks my own <a> it redirects him with same href which script rendered <a> has.

I can't use <script> tag or js script files.

<a href="/somegerantedhred" id="someId" style="display: none"></a>

<a href="somehow get same href"></a>


Solution 1:[1]

Not having access to the tags or the js files makes it almost impossible, the best thing I could come up with would be to use CSS to unhide the generated anchor by using #someId {display:block!important} so that you can use that generated tag as your anchor, however, I am not sure if this generated tag already has a value, if it doesn't, then nothing will be displayed in the screen and without access to the DOM with JS, it is pretty hard to find a solution to this matter.

#someId {display:block!important}
<a href="/somegerantedhred" id="someId" style="display: none">The hidden content</a>

<a href="somehow get same href">Your content</a>

Solution 2:[2]

If you can use onclick, then just put this in your source:

<a href="/somegerantedhred" id="someId" style="display: none"></a>

<a onclick="window.location.href = document.getElementById('someId').href"></a>

Solution 3:[3]

You can programmatically click the hidden link:

const hiddenLink = document.getElementById("someId");
const visibleLink = document.getElementById("visibleLinkId");

visibleLink.addEventListener("click", function(e) {
  e.preventDefault();
  hiddenLink.click();
});
<a href="/somegerantedhred" id="someId" style="display: none"></a>
<a href="#" id="visibleLinkId">Click me</a>

Solution 4:[4]

First, you must define an event handler or event listener for onClick in the button. you can get the href of link like this:

document.getElementById("someId").href;

Also, you can change the link value to other href like this:

window.location.href= url;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alvison Hunter
Solution 2 Mr Lister
Solution 3 Davfront
Solution 4 Ali