If you remove the id
of the element, it will not be able to recover it, unless you store it somewhere, but it would be complicated if there are several elements.
You can use other methods to maintain the id
in case you need to recover it in the future. One of them is to use dataset, creating an attribute data-id
, ex.:
<a id="" data-id="foo" href="">link</a>
By erasing the id
of the element, I can pull back by dataset:
function teste(){
var elemento = document.querySelector("a");
elemento.id = elemento.dataset.id;
//somente para ilustrar
elemento.innerHTML = "id recuperado!";
}
<a id="" data-id="foo" href="">id vazio</a>
<br>
<button onclick="teste()">Recuperar id</button>