Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!