My teacher gave use some code to work with and she told us not to touch the following as she has not taught it to us yet:
for ( i = 0; i < matrixOne.length; i++) {
document.getElementsByTagName("td")[i].addEventListener("click", function() {
cellClicked(this);
});
where matrix one is defined as:
var matrixOne = document.getElementsByTagName("td");
I need to make the cellClicked()
function work and I do not understand what this
is referring to when it is being passed as the parameter cellClicked(this);
.
Without knowing what this
represents I can not complete the cellClicked function as I do not now what is being passed. Can someone please explain how the keyword this
works here, i.e. how it's context is defined?
For future reference: This was solved, this
was referring to getElementsByTagName("td")[i]
and would be passed through if the cell was clicked on from the event listener.