...

View Full Version : Problem with comparing tagName in IF statement



ballaby
12-27-2011, 05: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!

Logic Ali
12-27-2011, 06:12 PM
tagName values are uppercase.

ballaby
12-27-2011, 06:16 PM
Thanks for the reply. I have tried changing it to:


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';
}

Unfortunately it still is not getting inside the IF. Any other ideas?

Thanks!

ballaby
12-27-2011, 06:17 PM
Oops, I pasted the wrong code in my last post. I mean I tried changing to this:


if(aObj[j].parentNode.parentNode.parentNode.tagName == 'LI'){
aObj[j].parentNode.parentNode.parentNode.className='active';
aObj[j].parentNode.parentNode.parentNode.getElementsByTagName('a')[0].className='active';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum