Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does jQuery offset(); work on td cells?

I'm trying to have a tool tip pop-up just slightly to the left of a couple of td cells in a table:

$('table.seafood td.prod4').hover(function() {
    var offset = $(this).offset();
    $("div.peekSeafood4").fadeIn(200);
    $("div.peekSeafood4").css('left', offset.left + 'px');
}, function() {
    $("div.peekSeafood4").fadeOut(200);
});

It's not working, throwing the tooltips far off to the side of the screen.

Does offset(); not work with td cells/tables?

like image 478
Yahreen Avatar asked Dec 02 '25 06:12

Yahreen


1 Answers

Yes, offset() works with table cells. This demo will show you it working at the most basic level.

I suspect the problem lies with $("div.peekSeafood4"), which will be positioned relative to its offsetParent element - you might need to make sure that the offsetParent for the matching element is the <body> element.

As @patrick_dw pointed out earlier, there's also the possibility that position() would give you the correct results, depending on where your tool tip pop-up is placed in the DOM.

like image 89
Andy E Avatar answered Dec 04 '25 20:12

Andy E