So I am trying to reposition an element each time a user clicks on an input element.
<script>
$(document).ready(function(){
$('input').each(function(index) {
var p = $(this).attr('id');
var position = p.position();
$this.focus(function(){
$('#desired_equity_help').css("left", position.left - 435 );
$('#desired_equity_help').css("top", position.top -20 );
$('#desired_equity_help').toggle();
});
});
});
</script>
‘desired_equity_help’ is the element that I am trying to toggle and reposition based on the input element clicked. Any ideas why this isn’t working?
Here is the HTML:
<div id="desired_equity_help" class="form_tooltip" >
<div class="tooltip_inner" >
<strong>Desired Equity</strong>
<p>Hello World! This is some dummy text.</p>
</div>
</div>
<span class="apply_form_label">Desired:</span><input style="width:110px" type="text" id="desired_equity" name="desired_equity"/><br/>
<span class="apply_form_label">Break:</span><input style="width:110px" type="text" /> at: <input type="text" style="width:110px" /><select><option>Independent Users</option></select><br/>
<span class="apply_form_label">Last One:</span><textarea rows="3" cols="50"></textarea>
</div>
Forget the foreach and apply the event straight to the selector like so…
Note: Using position will require your desired_equity_help element to belong to the same parent as your input elements. if this is not the case consider using offset instead