I have yet to start writing any code for this, but I will try to draft some pseudocode to explain my idea clearly. The concept is that when a user clicks and holds on a 'button' (which may not actually be a button), a movable DIV is spawned. Once the DIV is created at the mouse position (slightly offset so the mouse is inside the div), I want to change focus to the new DIV so it can be positioned on the screen. This involves some operations on the DIV, but those details are not relevant to my question.
In incomplete pseudocode, here is what I am aiming for; my main query here is how to switch focus:
<script>
function NewDiv()
{
var newDiv = CreateDiv(MouseX, MouseY);
GrabDiv(newDiv);
}
function CreateDiv(X, Y)
{
// Creating a new DIV in the DOM...handled.
// Making it movable with JQuery...done.
newDiv.style.left=(X - 3) + "px";
newDiv.style.top=(Y - 3) + "px";
return newDiv;
}
function GrabDiv(div)
{
// Here's where I need help...
}
</script>
<input type='button' onMouseDown='NewDiv();' value="Spawn a new Div" />
The crux of my question lies in the 'GrabDiv' function. Any advice or feedback would be greatly appreciated.
-- It seems there might have been a similar post before with a complex answer. Hopefully, this clarifies things and prompts a simpler solution. Fingers crossed!