ちょっと頑張ったので聞いてください!(笑) ↑の friends.each で回しながら onclick に get_friend(id) を仕込んで回ってる部分ですっごく詰まったんです。 初めはこう書いてたんですね。 for (var i = 0; i < 3; i++) { var elm = document.createElement("div"); elm.style.width = 50; elm.style.height = 50; elm.style.backgroundColor = "#ff0000"; elm.onclick = test(i); document.getElementById("target").appendChild(elm); } function test(str) { console.log(str); } すると HTML を表示した瞬間に