Here is the HTML code snippet:
<html>
<body>
<div id="pgContent">
<div id="studyOverlay">
<div id="studyContainer">
<div id="studyTest">
<div id="studyTestContainer">
<input class="dropInput">
<ul class="inputDrop">
<!--some <li>s-->
</ul>
</div>
</div>
</div>
</div>
</div>
I am looking to use jQuery to position the <ul>
element directly under the <input>
. Although this example only shows one set of input
and ul
, there could be multiple instances with the same classes.
Here is the jQuery code I have tried:
$('.dropInput').live('click', function() {
var offset = $(this).offset();
var height = $(this).height();
var width = $(this).width();
var top = offset.top + height + "px";
var right = offset.left + width + "px";
$(this).next().show();
$(this).next().css( {
'position': 'absolute',
'right': right,
'top': top
});
});
However, the positioning seems off in my implementation. I suspect it may have to do with the offsets and the nested div elements. Is there a way to correct this?
If you have any CSS solutions, that would be even more preferable!