Offset jQuery (); work on td cells?

I am trying to issue a tooltip a little bit to the left of a pair 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 does not work, throwing tooltips far toward the screen.

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

+3
source share
1 answer

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

I suspect that the problem is $("div.peekSeafood4")which will be positioned relative to the element offsetParent- you may need to make sure that the offsetParentcorresponding element is an element <body>.

@patrick_dw, , position() , , DOM.

+2

All Articles