Hi, i really donĀ“t know how to solve this, or why it isn't working...
first i try to grab all elements havung a specified class. no matter if it's 1 or 1000 elements.
After that all of those elements will have assigned an eventListener which then calls the function to replace the content from the clicked element in another specified element. (by taking and replacing inner html).
Usually i had the targetcontainer as 2nd argument in the eventlistener, but that didn't work at all.
See for yourself what happens.
Funny that when using the displayDate function everything works fine...
var spieler = document.getElementsByClassName("smallCard");
var i;
for (i = 0; i < spieler.length; i++) {
console.log(this.innerHTML);
spieler[i].addEventListener("click", ReplaceContentInContainer(spieler[i].innerHTML));
}
function ReplaceContentInContainer(content) {
var container = document.getElementById("fc");
container.innerHTML = content;
}
function displayDate() {
document.getElementById("fc").innerHTML = Date();
}
But like this it's working:
{
var spieler = document.getElementsByClassName("smallCard");
var i;
for (i = 0; i < spieler.length; i++) {
spieler[i].addEventListener("click", ReplaceContentInContainer);
console.log(spieler[i]);
}
}
function ReplaceContentInContainer() {
document.getElementById("fc").innerHTML = this.innerHTML;
}
But i don't understand why !Maybe someone could help me ou by explaining this to me.