> > As for the each() function -
I've given it some more thought, but I can't come up with a more
elegant solution (except perhaps for filter(), but I doubt that it
improves anything performance-wise). That's because we have to check
if the current link is in the current location, not the other way
around. I guess your scenario always applies to a navigation section,
so one could always narrow down the selector to links within the
navigation, which should cut down the number of times each() is run.
$('#nav a').each(function(){
var u = $(this).attr('href');
if( window.location.href.indexOf( u ) >= 0 && u.length > 1 ) {
$(this).css('background-color','#004040')
.css('color','#fff')
.css('font-style', 'italic')
.css('text-decoration', 'none');
}
});
> Regexes are definitely worth learning.
For some reason, they're coming to me slowly, but my good RegexBuddy
helps me in my trial and error pursuits. ;-) At least I've progressed
to be aware of lookahead/lookbehind.
Bernd