Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  184] [ 3]  / answers: 1 / hits: 29289  / 12 Years ago, fri, november 9, 2012, 12:00:00

While loading a page, I want to get the top of the panel. But it is showing errors.
In Firefox and IE its saying offset() is undefined and in Chrome the error is Uncaught TypeError: Cannot read property 'top' of undefined. Please Help out.



$(window).resize(function () {
tabPanelAdjust();
});

function tabPanelAdjust() {
var theTabPanel = $(.TabPanel);
var tabPanelTop = parseInt(theTabPanel.offset().top);
var winHeight = $(document).height();
tabPanelHeight = winHeight - tabPanelTop;
theTabPanel.css({ min-height: tabPanelHeight - 20 });
}

<div class=TabPanel>
</div>

More From » jquery

 Answers
43

There's nothing wrong with the code. include your code within document ready method. May be your code is fired before the div is loaded.



$(function(){
$(window).resize(function () {
tabPanelAdjust();
});

function tabPanelAdjust() {
var theTabPanel = $(.TabPanel);
var tabPanelTop = parseInt(theTabPanel.offset().top);
var winHeight = $(document).height();
tabPanelHeight = winHeight - tabPanelTop;
theTabPanel.css({ min-height: tabPanelHeight - 20 });
}
});


Here's a working fiddle:



http://jsfiddle.net/SX5U4/


[#82087] Thursday, November 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
claudiofredye

Total Points: 583
Total Questions: 101
Total Answers: 115

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;