Use myElem.parentNode. Also, consider using unobtrusive methods. If you don’t, at least use onclick instead of the horrible javascript: pseudo-protocol in the href attribute.
Also, doing that above will produce an error, since the style object doesn’t have a class. If you want to get the value of the parent’s class atribute, do this:
which works. I don’t know why using the “javascript:” syntax doesn’t work and to be honest I’m not especially interested because that is the most wrong way of doing things. The code above is a much better (though rather ancient and primitive) method. However, an even better and more modern method is this:
I’m trying to use your method to add an onClick event to some li tags and the function is only running one time and applying the action one time right off the bat before anything is clicked. Even so, if I click the li after the init function has run (after pageload) if I click an li but nothing happens. The function I attach is ment to togle a different background on and off. The li tags all have unique ids of BL(lowercase) and go from 0 - 8 here is the code.
function init(){
try{
var brandList = document.getElementById('brandDiv').getElementsByTagName('li');
for (var i = 0, j = brandList.length; i < j; i++) {
brandList[i].onClick = togle('bl'+i);
}
}catch(e){
alert("init() " + e.description);
}
}
function togle(id){
deselectAll(id);
var e = document.getElementById(id);
switch(e.className){
case 'liFirst':
e.className = 'liSelectedFirst';
break;
case 'liSelectedFirst':
e.className = 'liFirst';
break;
case 'li':
e.className = 'liSelected';
break;
case 'liSelected':
e.className = 'li';
break;
default:
alert('Unexpected class name');
break;
}
}