@prefix foaf: . foaf:topic . @prefix sioc: . sioc:container_of . @prefix rdf: . rdf:type rdf:Statement . @prefix rdfs: . rdfs:label "Embedded HTML5 Microdata Statement 115" . @prefix pwdr: . pwdr:describedby , ; rdf:object "\n\n\n\n AvidLearner:\n\n\n\nHere, my function sourceAlter only has the\nparameter e and therefore, I did not pass any\nparameters when I called the function, hence\nimage[i].addEventListener('click', sourceAlter)\nwithout any parentheses and parameters. However, what if my\nfunction requires two parameters, e.g. sourceAlter(a,\nb) , how do I pass on the parameters to said function?\n\n\nI don\u2019t quite understand how looping works in JavaScript. It\nsomehow does not make sense to me how for (...) in my\ncode above worked. I do know that it loops five times (as expressed\nin the conditional statement i < image.length ) and\nthat whenever an image with the order i\nis clicked, we run a function. But, when we click picture 1, 2,3\nand then 1 again, it somehow worked? There is not decrement in the\nfor loop, so how did it happen? Is the loop run over\nagain after each action (in this case, click (but doesn\u2019t have to\nbe necessarily a click))?\n\n\n\n\nSo to answer the first question, this isn\u2019t the simplest, but\nit is possible. This stack overflow answer is useful, and contains\nmultiple ways of doing it: \nhttps://stackoverflow.com/questions/256754/how-to-pass-arguments-to-addeventlistener-listener-function\nFor the second question, the loop only runs once. But one of the\nmain things the loop does is to add an onclick handler to each\nimage, using this code:\nnewImage.onclick = function(e) {\n var imgSrc = e.target.getAttribute('src');\n displayImage(imgSrc);\n}\n\nbecause that handler is added to each image, it is run every\ntime an image is clicked.\n" . @prefix schema: . rdf:predicate schema:articleBody ; rdf:subject .