I wrote this code to create a floating sidebar that sticks at top of the browser window. I am getting this error in chrome in line 3.
Uncaught TypeError: Cannot read property 'top' of null
this is causing a plugin I am using not to work.
$(document).ready(function(){
// Floating sidebars on page nodes
var sidebartop = $('.page-node .panels-flexible-region-node_layout-right').offset().top;
$(window).scroll(function(){
if( $(window).scrollTop() > sidebartop ) {
$('.page-node .panels-flexible-region-node_layout-right').css({position: 'fixed', top: '40px', margin: '0 0 0 650px'});
} else {
$('.page-node .panels-flexible-region-node_layout-right').css({position: 'static', margin: '-35px 0 0 0'});
}
});
});
I think, jQuery couldn’t find specified selector. I’am right if
returns empty array. Try to set some id for your sidebar (or which element you want to get offset) and rewrite code like
Also, you can search difference between
.first-class .second-classand.first-class.second-class(note for lack of space in second example) query rules.