Pure Javascript only please. - also I'm pretty noob, so sorry if my question is a little convoluted.
I'm operating on an htmlCollection var puzzleAreaContents
- which contains 16 <div>
tags
next we go inside a loop, cycling through the elements, adding a click event listener.
puzzleAreaContents[movables[i]].addEventListener("click", shiftPuzzlePiece);
when I click on the element, I have access to this
inside the shiftPuzzlePiece
function, "this" being the the <div>
tag I just clicked on.
I have two questions
- how / why does
shiftPuzzlePiece
function have access tothis
, the clicked dom element ? - how can I pass any arbitrary element to
shiftPuzzlePiece
without breaking it's current usability? -- How can I definethis
when I'm passing the function an object, so that it behaves the same or similarly to when it is called via the click event listener?
that is to say that it is not currently set up to receive arguments
ex: shiftPuzzlePiece(some_arg)