ballaby
12-27-2011, 04:47 PM
I have a Javascript function that is highlighting the menu in one of my courses. I am having a problem getting into an If statement in some cases. Here is my code:
function hilightCurrent() {
var nav = document.getElementById('nav');
if (nav == null) {
return;
}
var checkIndex = hreftable[__currpage];
var aObj = nav.getElementsByTagName('a');
var found = false;
while ((found == false) && (checkIndex > -1)){
for(j=0; j < aObj.length; j++) {
if(aObj[j].href.indexOf(index[checkIndex].href)>=0) {
aObj[j].className='active';
alert("parent tag = " + aObj[j].parentNode.parentNode.parentNode.tagName);
if(aObj[j].parentNode.parentNode.parentNode.getElementsByTagName == 'li'){
aObj[j].parentNode.parentNode.parentNode.className='active';
aObj[j].parentNode.parentNode.parentNode.getElementsByTagName('a')[0].className='active';
}
found = true;
break;
}
}
checkIndex--;
}
}
The alert I have in there currently is returning LI in the case where I want to get into the IF statement right below it. So the alert comes back as LI and then I am checking if it is LI but for some reason it doesn't get into that if statement. Can anyone help or have any ideas?
Thanks!
function hilightCurrent() {
var nav = document.getElementById('nav');
if (nav == null) {
return;
}
var checkIndex = hreftable[__currpage];
var aObj = nav.getElementsByTagName('a');
var found = false;
while ((found == false) && (checkIndex > -1)){
for(j=0; j < aObj.length; j++) {
if(aObj[j].href.indexOf(index[checkIndex].href)>=0) {
aObj[j].className='active';
alert("parent tag = " + aObj[j].parentNode.parentNode.parentNode.tagName);
if(aObj[j].parentNode.parentNode.parentNode.getElementsByTagName == 'li'){
aObj[j].parentNode.parentNode.parentNode.className='active';
aObj[j].parentNode.parentNode.parentNode.getElementsByTagName('a')[0].className='active';
}
found = true;
break;
}
}
checkIndex--;
}
}
The alert I have in there currently is returning LI in the case where I want to get into the IF statement right below it. So the alert comes back as LI and then I am checking if it is LI but for some reason it doesn't get into that if statement. Can anyone help or have any ideas?
Thanks!