$(document).ready(function(){ path = window.location.pathname.split('/'); mypath= '/'+path[1]+'/'+path[2]; $('.portletNavigationTree a').each(function(){ if($(this).attr('href') == mypath){ /*console.log($(this).parent());*/ $(this).addClass('navTreeCurrentNode'); $(this).addClass('navTreeCurrentItem'); } }); });