Aleksandar Aleksandar - 2 months ago 6
Javascript Question

I do not see displaying a unique object ID in JavaScript

On the screen we show four strings, but when I click on the latest string only he does, why does not work the first three links?

[enter link description here]


[1]
https://jsfiddle.net/a35wL5ht/

Answer

replace

document.getElementById("show_test").innerHTML += '<div><a href="#" id="bt_' + item + '">click</a></div>';

with

var el = document.createElement("div");
var a =  document.createElement("a");
a.innerHTML = "click";
a.id = "bt_" + item;
el.appendChild(a);
document.getElementById("show_test").appendChild(el);