On Aug 16, 5:13 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> One way to avoid marking external links as the current page would be
> to begin with an if statement:
>
> if (location.hostname == 'www.mysite.com') {

The main problem with that is you've normally got to add several
domains: your test server(s) (i uses aliases for localhost along with
apache named vhosts), mysite.com, and www.mysite.com. It's easy to
forget to add one of them.

> you might be able to avoid the next line by using this:
>
> var loc = location.pathname;

That's a good trick - i wasn't aware of 'location'. So the modified
code looks like:

        var loc = location.pathname;
        var sel = '[EMAIL PROTECTED]"'+loc+'"]';
        $(sel).css('background-color','#004040')
                .css('color','#fff')
                .css('font-style', 'italic')
                .css('text-decoration', 'none');

Or, if you're a space-saving fanatic:

$('[EMAIL PROTECTED]"'+location.pathname+'"]').css(...);


That can ALMOST be done in plain CSS, without the JS scaffolding.

:)

Reply via email to