On 7/24/07, Mitchell Waite <[EMAIL PROTECTED]> wrote:

 jQuery.fn.toggleVis = function() {

        if(chesireCat.style.visibility == 'hidden') {

           chesireCat.style.visibility = 'visible';

        } else {

           chesireCat.style.visibility = 'hidden';

        }

};


That works for you??? (works as in functions properly, not as in "I'm ok
with this"), because I couldn't get it to in either Firefox or IE 7.

In fact, I was expecting this not to work. As I explained in our off-list
communication, that cannot possibly work because there is no variable named
"chesireCat" defined within the toggleVis(). If I correct the spelling
mistake and change "chesireCat" to "cheshireCat", then it works, but only in
Internet Explorer (which is generally a Bad Thing, you *want* things to work
cross-browser[1]).

If my original solution was too complex for you, here's a simpler solution
(although it lacks the reusability of mine):

     /* toggle visibility */
     $('#toggle').click(function() {
           // Remember, a jQuery object acts like an array of all elements
selected by a
           // particular selector (in this case, "#cheshireCat"), so we
access individual
           // elements through numbered array indexes (starting with 0)
           var cheshireCat = $("#cheshireCat")[0];
           if(cheshireCat.style.visibility == 'hidden') {
               cheshireCat.style.visibility = 'visible';
           } else {
              cheshireCat.style.visibility = 'hidden';
           }
       });


[1] jQuery helps *a lot* in this regard, but it doesn't handle everything.

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com

Reply via email to