First: This is what you should consider server-side. It is much, much, much simpler and more reliable.
In your code, only the href of the first link is compared, since attr returns the property value of the first link. You need to iterate over the links to find the right one.
var loc = window.location.href; $("#topNavigation li a").each(function() { if(this.href == loc) { $(this).addClass('currenthover'); } });
source share