I have the following HTML code:
<div id="ID_unique"></div>
<span class="a_random_class">a</span>
<span class="a_random_class">b</span>
<span class="a_random_class">c</span>
And the Javascript
<script>
setTimeout(function() {
var element = document.getElementById("An_ID");
Array.prototype.forEach.call(document.querySelectorAll(".a_random_class"), function(e) {
var example = element.appendChild(e.cloneNode(true));
example.className += " timeline-date";
var div = document.createElement('div');
div.id = "id_frame";
div.appendChild(example);
element.appendChild(div);
});
}, 300);
</script>
It will wrap the result of the cloneNode inside a HTML div, and those generated div tags will have the same ID id_frame ... However since in HTML all IDs must be unique, how can I tell Javascript to generate a unique ID for each result?