1
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. Obs: the code works but it is not set the "src" that should be changed according to button on which I clicked.
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);
}
}
treat as 0, i is part of an iteration, it is not the problem q want to solve, the want to solve is the fact that the values of addeventlistener are fixed, IE, it only uses the link of the last link nail.
– Vinícius França