Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
JQuery why does .offset() not return value?

Hi i get a JS error in my browser inspector. But i dont understand whats wrong with my Jquery code. And why he consider this variable as undefined ... Could someone help me ?

The code works well; but i would prefer to remove the error: Uncaught TypeError: varposlist is undefined

This is my js code:

 $(function(){
var pane = $('.scroll-pane');
pane.jScrollPane({
    });
var api = pane.data('jsp');

    if(typeof localStorage!='undefined') {
        //Get var from local storage
        var menu = sessionStorage.getItem("menu");
        var yposistock_rule = sessionStorage.getItem("yposistock_rule");
        

        //Check menu view mode
        if(menu == "arbo") {
            // defined top from a#on anchor
            var varposchapter = $('a#on_menuchapter').offset();
            //add - 285 to put at same level than title
            var vartop1 = varposchapter.top -285 -yposistock_rule;
            if(scrollauto_rule == "oui") {
                sessionStorage.removeItem("yposistock_rule");
            };
            api.scrollTo(0, vartop1);
            return false;
             
        }
        else{   
            // defined top from a#on anchor
            var varposlist = $('a#on_menulist').offset();
            //add - 285 to put at same level than title
            var vartop2 = varposlist.top -285 -yposistock_rule;
            if(scrollauto_rule == "oui") {
                sessionStorage.removeItem("yposistock_rule");
            };
            api.scrollTo(0, vartop2);
            return false;
        }
    }
});

Any idea ? Thanks a lot.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The only thing I can think of is this line:

$('a#on_menulist').offset();

The # selects the element with the same ID. Unless you have an element with id=on_menulist, this code cannot find the id which then cannot find the offset.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda