On Aug 16, 6:28 pm, Bernd Matzner <[EMAIL PROTECTED]>
wrote:
> how about plain and stupid checking if the current url is in the link?
...
i hadn't considered making sure it works when people link from
external sites. :/
> $('a').each(function(){
> if( window.location.href.indexOf( $(this).attr('href') ) >= 0 &&
The main disadvantage (admittedly small) is that this will run the
function for every link on a page, whereas the href=... selector is
faster.
> The idea behind it is that if you have some scenario like users coming
> from Google ads, with extra GET variables in the URL, it should still
> work, except in scenarios where you have dynamic pages using get
> variables: in this case the current link is only highlighted if it's
> identical with the current page. The extra length clause is to leave
> '#' or '/' links out.
That's why Karl's solution is so slick: the location.pathname var
doesn't include GET params and such. The one special case i can see is
that '/some/path/' actually resolves to /some/path/index.php (or
similar). On my sites i never link to the index file directly (only to
the dir, with trailing slash), but if a site has multiple maintainers
it would be easy to get a mixture of links which contain (or don't)
the index.php/html/asp file.