Change link of two links whose id are equal to js

-3

I needed to duplicate a code from a link, whose id is the same (I can not change, nor can I actually). I need to change the text of this link. I did this:

document.getElementById("send").innerHTML = "Enviar itens";

But it only changes the text of the first link, and as said, I need to change the text of the two links.

Link code:

<a id="send" href="rota" class="buy send">Send</a>

<a id="send" href="rota" class="buy send">Send</a>

I needed to duplicate because I do not have access to the "pure" html, I call the content through controls on my CMS platform.

    
asked by anonymous 08.11.2018 / 20:45

1 answer

1

document.getElementById() only supports node name at a time and returns only a single node, not an array of nodes. You have several different options:

You can implement your own function that takes multiple ids and returns multiple elements.

You can use document.querySelectorAll () which allows you to specify multiple ids in a CSS selector string.

You could put common class names on all of these nodes and use document.getElementsByClassName () with a single class name.

    
08.11.2018 / 20:58