If you remove the id
from the element, you will not be able to retrieve it, unless you save it somewhere, but that would be tricky if it's multiple elements.
You can use other methods to keep the% w / o of the element if you need to recover it in the future. One of them is to use dataset , creating a id
attribute, eg:
<a id="" data-id="foo" href="">link</a>
When I delete the data-id
of the element, I can then pull it by picking up the 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>