I'm trying to add a click event to all the elements I add to the table. I do this at the same time I create the lines and cells. Note: the code works but the "src" that should be changed according to the button I clicked on is not set.
function preecheTable(){
row = document.createElement("tr") //cria uma linha vazia
celula = document.createElement("td"); //cria uma celula de dados
link = document.createElement("button");
//link.setAttribute("href", data[i].link);
link.innerHTML = data[i].titulo;
celula.appendChild(link);
row.appendChild(celula);
table.appendChild(row);
//cria a relacao do iframe com o episodio escolhido
celula.addEventListener("click", relationIframe(data[i].link, tableName));
}
function relationIframe(link, Nome){
var video;
if(Nome == "tablePodcast"){
video = document.getElementById("sec-podcast").getElementsByTagName("iframe")[0];
video.setAttribute("src", link);
}else if(Nome == "tableEsport"){
video = document.getElementById("sec-esport").getElementsByTagName("iframe")[0];
video.setAttribute("src", link);
}else if(Nome == "tableGameplays"){//GAMEPLAYS
video = document.getElementById("sec-gameplays").getElementsByTagName("iframe")[0];
video.setAttribute("src", link);
}
}