I am wondering how to place a hidden box div into an input text that is currently in focus?
<input type="text" class="target" name="some_name">
<input type="text" class="target" name="other_name">
<input type="text" class="target" name="another_name">
<input type="text" class="target" name="some_other_name">
other HTML ....
<div id="hidden">This div is hidden somewhere in the page,
and only visible if any of the above input text is in focus.
Once another input is in focus, this box is moved
relatively positioned (next, top or bottom) to the focus input.
This should be hidden if no input is in focus.</div>
I notice a plugin: http://benalman.com/projects/jquery-outside-events-plugin/
but no idea if that is what I need at all.
Any hint or direction is very much appreciated. Thanks
inputelements cannot have child elements, so you can’t put it inside in the DOM sense. You could put it on top of the input, e.g.:Live copy
There we’re using
offsetto get the position of the focussed input and then positioning the “hidden”divon top of it and showing it; onblurwe hide it again. We usedatato remember which input the div is showing for so we only hide it when we see the correctblur(just being defensive).(Note that I’ve assumed the
idvalue on thedivwill be"hidden", not"#hidden"as in your HTML example. You don’t write the hash mark (#) in theidattribute, that’s just the CSS indicator that what follows is anidin a selector.)