jQuery.fn.toggleVis = function() {
       if(this.style.visibility == 'hidden') {
         this.style.visibility = 'visible';
       } else {
          this.style.visibility = 'hidden';
       }
};

doesn't "this" here refer to the jquery object... I don't think jquery
object has a style attribute, or does it?

-GTG


On 7/24/07, Stephan Beal <[EMAIL PROTECTED]> wrote:


On Jul 25, 12:41 am, "Mitchell Waite" <[EMAIL PROTECTED]> wrote:
> I know this is trivial but what it turned out I needed was something
this
> simple
>
> jQuery.fn.toggleVis = function() {
>
>         if(chesireCat.style.visibility == 'hidden') {
>
>            chesireCat.style.visibility = 'visible';
>
>         } else {
>
>            chesireCat.style.visibility = 'hidden';
>
>         }
>
> };

Eeeek! What you're doing here is adding a toggleVis() function to ALL
selectable jQuery elements, but then in the function you're applying
the change to a specific element. Thus this will trigger your
function:

$('div').toggleVis();

that will toggle the cheshireCat element, not the selected element(s),
which certainly isn't desired.

What i *think* you meant was to either make that a standalone function
(not using jQuery.fn.) or:

jQuery.fn.toggleVis = function() {
       if(this.style.visibility == 'hidden') {
          this.style.visibility = 'visible';
       } else {
          this.style.visibility = 'hidden';
       }
};




Reply via email to