Hi,
I'm a bit confused about how to call plain JavaScript functions on a selected element or access an elements properties.
For example to set an onmousemove handler for a canvas element I tried this:
- <html><head><script>
- function mouseMoveHandler(event) {
- // do some thing
- }
- function init() {
- var canvas = $("#myCanvas");
- canvas.onmousemover = mouseMoveHandler;
- }
- $(function(){init();});
- </script><body>
- <canvas id="myCanvas" height=100 width=100></canvas>
- </body></html>
but that does not work. I could fix that by changing line 7 to:
- canvas[0].onmouseover = mouseMoveHandler;
Is there a better way to achieve this result?
Why can't I just access the properties without that nasty looking array operator? I selected the element by it's ID so why do I have to select the first element in the returned value (set)?
What is returned by the selector(s) (what kind of data)?
Thanks for clarification!
Lutz