A
A
Anton2018-03-21 11:34:20
JavaScript
Anton, 2018-03-21 11:34:20

How to replace href when clicking on a link button?

When you click on Buy, the text is replaced with Already in the cart.
How can I change the link to /cart/?

<script>
var about_bears = "Уже в корзине";
</script>

<a 
onclick="document.getElementById('<?=$arCurOffer['ID']?>').innerHTML = about_bears"
data-element-id="<?=$arCurOffer['ID']?>"
href="javascript:void(0);"
class="cartochka__btn-to-basket btn-black cartochka__btn-to-basket_contact-lens">
<div id="<?=$arCurOffer['ID']?>">Купить</div>
</a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Space, 2018-03-21
@ruslite

Google: "js change attribute value"
Response:
document.getElementsByTagName("a")[0].setAttribute("href", "/cart/");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question