Well this has me stumped. I hope this isn't to complicated to follow.
First here's the code (modified to show the problem only and keep it short)
function GetCurrentObj() {
var alldivs = document.body.getElementsByTagName('div');
for (var d = 0; d < alldivs.length; d++) {
if ((alldivs[d].getAttribute('data-type') == 'content') && (alldivs[d].style.display != 'none')) {
alert(alldivs[d].style.display);
var currentobj = alldivs[d].getAttribute('id');
}
}
return currentobj;
}
As you can tell by the code, I am trying to find the div that is currently being displayed. It then returns the currently displayed div where another function then makes a new array, in a global array, with the same name as the div. This functions has to figure out what div is displayed so other functions know where to store settings for tabs/divs or where to retrieve settings upon a return to the tab/div.
If you haven't guessed this system is for handling large sets of data, and this function is for several pages. So it has to figure out on its own which div is currently being displayed, without any external input.
The problem only occurs when the page first loads, that function can not see what div has a display != 'none' (I have also tried display == 'block', display == 'static', ect) . If I run this function that alert (which is there for debugging) will give me a blank alert for each div that has a "data-type" attribute value of "content" in the page.
All the tabs but the primary tab have their "display" set to "none" and to be sure I have checked the other divs "display" settings using firebug.
Now once I click a tab it all works fine, I can even return to the first tab and have it work fine. It is just after the page is loaded this function can't tell which div is currently visible.
Any thoughts?