Leaked files
X Men Origins Wolverine F. By bernneyls Nov 30, 14. Applications. If you think you have the skills, feel free to apply!
X men origins wolverine oyunu indir gezginler
X-men origin wolverine game x-men vivendi x-men video games zuma zuma game x-men wolverineQ:
javascript adding event listener for dynamically created element
I want to add an event listener for dynamically created button elements. This is my code:
//initialize the test buttons
var btn1 = document.createElement("button");
btn1.setAttribute("type", "button");
btn1.innerHTML = "Test";
btn1.addEventListener("click", alert("Test"));
document.getElementById("button").appendChild(btn1);
The problem is that I get a
TypeError: btn1.addEventListener is not a function
error.
Can anyone help me on how I can add an event listener for dynamically created button elements?
A:
You need to give it a function, not a string.
var btn1 = document.createElement("button");
btn1.setAttribute("type", "button");
btn1.innerHTML = "Test";
btn1.addEventListener("click", function() {
alert("Test");
});
document.getElementById("button").appendChild(btn1);
A:
You should actually call addEventListener on an Element, not just a reference.
var btn1 = document.createElement("button");
btn1.setAttribute("type", "button");
btn1.innerHTML = "Test";
btn1.addEventListener("click", alert("Test"));
document.getElementById("button").appendChild(btn1);
Soccer Bowl
Soccer Bowl, abbreviated as SB, is an association football club from Sundsvall, Sweden that is active in the Swedish top football league Allsvenskan and Swedish Cup. Their home ground is Lundvalls IP (Lundvallen IP) in Sundsvall, with their away games in winter played at the Letohallen, Lund.
In 2006 the club participated in the qualifying round of the UEFA Intert ac619d1d87
Related links:
Comments