Saturday, April 28, 2018

Getting ID

Today's problem:I would like to return the id of picture element
that the user clicks on, and have that become the 'ball' for the easy
drag functions. In effect, the puzzle piece the user is working with.

To date, I know the type of the object. I can also query for the Id.
It's going to be a wiring problem...



https://plnkr.co/edit/krW9OGf7Z6l7eN5EHSzn?p=preview

Here is the problem: 'this' becomes undefined if we move things to a helper
function. It has to do with how the computer allocates space for variables: first on
load, then in the runtime.


We are going to have to pass the pertinent information to the helper function
as a parameter.

Our information goes into the (as per documentation) idStr variable.


Which works fine for the main program.





Problem is, the variable in the function is local to it and means nothing outside. There
is only one solution: stay within the function. Yep, the ball moves!!






Test of fire: what happens if we add a second ball...Works fine; we just have
to double-click on the ball we want to move.

https://plnkr.co/edit/krW9OGf7Z6l7eN5EHSzn
https://developer.mozilla.org/en-US/docs/Web/API/Element/id
https://javascript.info/function-basics

                                     *     *     *

Changed from 'ondbleclick' for 'onmouseenter'. Now things run very smoothly.


https://plnkr.co/edit/9fXFNGSIHnV9tjh3aLLn?p=info

No comments: