I need to find the correct .offset()-position of a tabled TD-elements within a Drupal7-generated HTML-site (jQuery_update installed). I use
$('#contenttable td').each(function(){
console.log($(this).offsetParent());
console.log($(this).offset().left);
});
within my
jQuery(function($) {
//$(document).ready(function(){
of my script.js to get the offset().left-position but the console allways traces me ‘0’ for all TDs.
When I use the Safari Developer Console the output of
jQuery('#contenttable td:nth-child(2)').offset().left
is ‘1728’, so it seems to work at all. But why doesn’t it work from within my DOCUMENT.READY?
The .offsetParent() is BODY by the way… And changing some of the parents DIV’s position to absolute or relative didn’t give any change, too.
THNX!
edit: seems not to work for any element at all.
Unfortunately,
jQuery.offsetdoes not work on hidden elements, because the browser doesn’t bother rendering them at all. So if possible, you need to make the element visible in order to get itsoffset. According to jquery: get the offset of hidden element , you should be able to call.show()on the table/content, get the desiredoffset, then call.hide()on it. This show/hide should not be apparent to the user, as it won’t repaint the page since it’s in the same execution event.