I have an ajax script that loads list items on my page. Depending what tab the user clicks on, different lists will open. The list items are unique. But my if clause figures out what list I'm in then calculates the offset for a popup window.
if(varType == 'search')
{
p = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_search').offset();
//p.top = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_search').offset().top - $(window).scrollTop();
//p.left = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_search').offset().left();
}
else if(varType == 'fuv')
{
p = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_fuv').offset();
}
And then I do this if the offset is 0, 0:
while(p.top == 0 || p.left == 0)
{
if(varType == 'search')
{
p = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_search').offset();
}
else if(varType == 'fuv')
{
p = $('.dv_variable_' + subjectId + '_' + varNumber + '_' + varSequence + '_fuv').offset();
}
}
Now if I do alert(p.left+" "+p.top) between the ifs above and the while loop, the offset is calculated, otherwise without the alert I always get 0,0.