It is very likely that this javascript function was placed before the actual html was loaded. Do something like add a condition
var container = $('.container');
if (container.length) {
var content= container.offset().top;
...continue to set up the menu
}