There are two links that should lead to different sections of the link depending on the anchor. I get the necessary links in link1 and link2 . Question: how now to transfer them to the links themselves without correcting html ?
var link1 = document.getElementsByClassName("link1").href = "link#one"; var link2 = document.getElementsByClassName("link2").href = "link#two"; console.log(link1, link2); <a class="link1" href="link">ссылка1</a> <a class="link2" href="link">ссылка2</a>
getElementsByClassName("link1")way, your code does not work, sincegetElementsByClassName("link1")returns a collection - Grundyhtml- Vasyacollection.prop=10and thepropproperty is set for everyone. - Grundy