How to add onclick event while creating an element with JavaScript?
问题 I have a script where I'm appending elements to a list. I would need that when I click the element a function is called, and for this function the value of a variable when creating the li is needed (it's the li content). I've checked solutions like adding newLi.onclick = function(){...} . The problem with this solution is that I'm not getting the right value in the function, I get the value of another element in the list. Right now this is how I'm creating the elements: var ULlist = document