Ganeshji,
Correct, As Aaron states above, 'this' refers to the jQuery object, hence
this code will not work.

Mitch,
As I can see it I think you're misunderstanding how jQuery works from the
outside at quite a fundamental level. Did you run through the tutorials at
http://docs.jquery.com/Tutorials ? At the very least, John and Joern's
tutorials - the top two - are an excellent introduction.
Also IIRC from your other posts you aren't overly-familiar with JavaScript
itself. I don't know of other people's opinions and am not speaking for the
jQuery community, but I would really recommend learning JavaScript on its
own to a competent level before attempting to use jQuery, otherwise it's
hard for you to know which conventions, problems and bits of code are
JavaScript, and which are jQuery. It would be like trying to learn MFC
(Microsoft Foundation Classes - the old MS C++ class hierarchy wrapping the
Windows API) before being able to code in C++.
Granted, jQuery is massively more simple than MFC, but JavaScript is a much
more complicated language than some appreciate (I'm currently struggling
with some aspects). Walk before you can run.

--rob

On 7/25/07, Ganeshji Marwaha <[EMAIL PROTECTED]> wrote:

> 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';
>        }
> };
>
>
>
>



--
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

Reply via email to