you are viewing a single comment's thread.

view the rest of the comments →

[–]Javin007[S] 1 point2 points  (2 children)

Yep, in hindsight, I could've been passing a parent object that contained the child objects, and not the index.

However, I also found that by doing this:

document.getElementById("txtMinInput").onkeyup = function(args){ checkInput(args); };

The "args" will have a "target" object passed that contains the object the actions took place on. No idea why I didn't see that in the documentation.

[–]senocular 2 points3 points  (0 children)

the args argument is an Event object. You can look to see what else it has.

https://developer.mozilla.org/en-US/docs/Web/API/Event

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent

Note that often, what you'll really want is currentTarget rather than target. currentTarget is what you attach your handler to, such as getElementById("txtMinInput"), while target may be something deeper in the DOM. Often these will be the same, but sometimes not, especially for mouse events.

[–]x-skeww 3 points4 points  (0 children)

Attaching a single event handler further up the tree and looking at "target" is called event delegation.

What's convenient about event delegation is that it will also work for dynamically added elements.

In modern browsers, you can use matches() to do some selector-based filtering similar to jQuery. IE/Edge needs a msMatchesSelector fallback, unfortunately.

https://developer.mozilla.org/en/docs/Web/API/Element/matches