0

I would like to add an Event Handler for all of my <td> tags. I've tried the following:

var allSquares = document.getElementsByTagName("td");

for (var i = 0, len = allSquares.length; i < len; i++){
allSquares[i].addEventListener('ondragover', allowDrop, false);

}

Anyone has an idea why it didn't work? Thanks ahead

0

2 Answers 2

2

Generally event names passed to addEventListener do not start with "on".

allSquares[i].addEventListener('dragover', allowDrop, false);
Sign up to request clarification or add additional context in comments.

Comments

1

With the W3-method addEventListener you don't put an "on" before the event's name (like you do for Microsoft):

allSquares[i].addEventListener('dragover', allowDrop, false);

See Quirksmode's article on the two advanced event registration models.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.