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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With