views:

24

answers:

1

i have 5 elements in my array & in my html there are six div's

when the loop goes for sixth element and the corresponding element is not present in the array, then the div should be hidden otherwise it should be visible

The problem i am facing with my current code is that even sixth element is not there, it is showing div as visible,

var qn_id=0;
for (var k=1; k<=6; k++){
var elem=getElemById_html("menu_"+k+"_container");
    for (var key in NavArray) {
        if (key > qn_id) {
            qn_id=key;
            break;
        }   
    }
    if (NavArray[qn_id]) {
    elem.style.display="block";
    } else {
    elem.style.display="none";
    }
}
A: 

if (NavArray[qn_id]) is not correct.

Try this:

if (typeof NavArray[qn_id] !== 'undefined') { ...
Māris Kiseļovs