function initHLI() { // Find all li elements var lis = document.getElementsByTagName('li'); var hlis = []; for (var i = 0; i < lis.length; i++) { // Find all li elements with hli in their class attribute while allowing for multiple class names if (/\bhli\b/.test(lis[i].className)) hlis[hlis.length] = lis[i]; } // Loop through the found li elements, // find the first tag inside the li to find the href, // and attach a function to the li.onclick action to redirect there for (var i = 0; i < hlis.length; i++) { if (hlis[i].getElementsByTagName('a')[0].target && hlis[i].getElementsByTagName('a')[0].target=="_blank") { hlis[i].onclick = function() { var newWin = window.open(this.getElementsByTagName('a')[0].href, 'newWin'); newWin.focus(); } // and remove href from a tag to prevent double-clicks hlis[i].getElementsByTagName('a')[0].onclick = function() { return false; } } else { hlis[i].onclick = function() { location.href = this.getElementsByTagName('a')[0].href; } } } } if(document.getElementById && document.createTextNode) { addEvent(window, 'load', initHLI); }