I\'ve seen this question posed once or twice before, but never with an answer that applies to my problem (as far as I know). I have a tooltip that appears when a link is cli
Instead of using position()
like in your example:
var link = $('#mymenu a');
var tooltip = $('#mymenu #tooltip');
link.click(function(){
tooltip.css('left', $(this).position().left);
});
you can use subtraction of the element's offset()
with offset()
of it's parent (not necessarily the closest parent):
var parent = $('#mymenu');
var link = $('#mymenu a');
var tooltip = $('#mymenu #tooltip');
link.click(function(){
parent.css('position', 'relative');
tooltip.css('left', $(this).offset().left - parent.offset().left);
});
It returns the same value as position()
but works correctly in both FF and Chrome.