I want to create dynamic list of hrefs using JavaScript, for that I need the link to execute some function each time the user click on the href BUT with different arguments.
Code: What I tried so far is this!
for(var k in LIST_OF_ARGUMENTS){
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href","#");
// K here is the argument of myFunction
a.setAttribute("onclick","myFunction("+k+")")
a.appendChild(document.createTextNode(k))
li.appendChild(a);
a.onclick = ...? Or better stilla.addEventListener(...);? Remember to lock the scope ofkthough, otherwise it won't work as you expect.kis creating different strings each iteration of the loop.kappropriately.kvalue and then in yourmyFunctionaccess it to get your value, instead of trying to create multiple onclick values