简体   繁体   中英

Replace href with another href from the same page

I want to make a button that will have href that is same as another button.

I have one button on my website that not all users see but its almost hidden and hard to reach. This button has specific UR for every user and contains his ID. On another page I want to create a button that will copy the same href from the other button:

Here is an example:

<div class="row exsisting-button button-hard-to-reach">
    <a href="https://doman.com/user/543456/offers" class="your-offers">See my offers</a>
</div>


<div class="row new-button">
    <a href="" class="new-button">Here are you offers</a>
</div>

You can use querySelector to find element and getAttribute getAttribute to set get href

 document.querySelector('.btn-href').setAttribute('href', document.querySelector('.your-offers').getAttribute('href') );
 <div class="row exsisting-button button-hard-to-reach"> <a href="https://doman.com/user/543456/offers" class="your-offers">See my offers</a> </div> <div class="row new-button"> <a href="" class="new-button btn-href">Here are you offers</a> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM