There is an update code address link by clicking on the checkbox
var w = document.querySelector('#wall'), a = document.querySelectorAll('a')[0]; w.onclick = function() { if (w.checked) { a.setAttribute('href', a.getAttribute('href').replace(/^(.*\&scope\=(?:[A-Za-z_0-9-]+\,?)*)[^&]*(\&.*)$/, '$1wall,$2')); } else { a.setAttribute('href', a.getAttribute('href').replace(/^(.*\&scope\=)[^&]*(\&.*)$/, '$1$2')); } console.log(a.getAttribute('href')); } var m = document.querySelector('#messages'), a = document.querySelectorAll('a')[0]; m.onclick = function() { if (m.checked) { a.setAttribute('href', a.getAttribute('href').replace(/^(.*\&scope\=(?:[A-Za-z_0-9-]+\,?)*)[^&]*(\&.*)$/, '$1messages,$2')); } else { a.setAttribute('href', a.getAttribute('href').replace(/^(.*\&scope\=)[^&]*(\&.*)$/, '$1$2')); } console.log(a.getAttribute('href')); } <a href='https://oauth.vk.com/authorize?client_id=4113&scope=notify,&redirect_uri=https://oauth.vk.com/blank.html&response_type=token'><b>ссылке</b></a> <input type="checkbox" id="wall">Отправка посто <br> <input type="checkbox" id="messages">Работа с сообщениями <br> Everything works, but if you insert another link before the link, the code stops working. I tried changing a = document.querySelectorAll('a')[0-на другие]; on a = document.querySelectorAll('#someid')[0]; To the link I substituted id="someid" . He began to change the first link, although the first link had no id at all.