Great, I'm glad you got it working, Steve.

Check out Dan's followup comments for some good ideas on optimizing your
code.

I'd add one more thing to that. I suggest using the $ prefix on variable
names only when you are storing a jQuery object in that variable.

For example:

    var $this = $(this);  // good!

But I'd change:

    var $ref = $("#calendar #navleft").attr("href");

To:

    var href = $("#navleft").attr("href");

Following this convention really helps keep straight which variables are
jQuery objects and which aren't - the $ in the name links it visually to the
$ in a $() call.

So in Dan's example:

    var jCalNavLeft = $("#calendar #navleft");
    var $ref = jCalNavLeft.attr("href");
    jCalNavLeft.attr("href", $ref.slice(0, -1)+'0');

I would use:

    var $navleft = $("#navleft");
    var href = $navleft.attr("href");
    $navleft.attr( "href", href.slice(0,-1) + '0' );

Or, since the href variable isn't used anywhere else, simply:

    var $navleft = $("#navleft");
    $navleft.attr( "href", $navleft.attr("href").slice(0,-1) + '0' );

Or even this (which is probably the way I'd code it myself):

    var navleft = $("#navleft")[0];
    navleft.href = navleft.href.slice(0,-1) + '0';

Note that I took the $ off the navleft variable name, because in this
example it's not a jQuery object.

There's more than one way to skin a cat! :-)

-Mike

> From: SteelSoftware
> 
> What I was trying to do was edit the last characer based upon a few
> conditions so that a show/hide function would work with and without
> javascript.
> 
> As well as the errors you spotted, when i was setting the href I was
> setting it to #calendar .nav, and not to #calendar #navleft. The
> addition of .text() on the end of .href() was just me trying things to
> see if they worked. Thankfully now, the script works. The whole thing
> now looks like this:
> 
> $("#toggle").click(function(){
>                 $("#calendar .arc").toggle();
>       $("#calendar .arc").Highlight(1000, '#ff9');
> 
>       var $this = $(this);
>       if($this.is ('.show'))
>       {
>               $this.removeClass('show');
>               $this.addClass('hide').empty().append('Show archived
members');
>               var $ref = $("#calendar #navleft").attr("href");
>               $("#calendar #navleft").attr("href", $ref.slice(0, -1)+'0');
>               var $ref = $("#calendar #navright").attr("href");
>               $("#calendar #navright").attr("href", $ref.slice(0,
-1)+'0');
>       }
>       else
>       {
>               $this.removeClass('hide');
>               $this.addClass('show').empty().append('Hide archived
members');
>               var $ref = $("#calendar #navleft").attr("href")
>               $("#calendar #navleft").attr("href", $ref.slice(0, -1)+'1');
>               var $ref = $("#calendar #navright").attr("href")
>               $("#calendar #navright").attr("href", $ref.slice(0,
-1)+'1');
>       }
>       return false;
> });
> 
> Many thanks again Mike :)

Reply via email to