Rob:
Unfortunately my code does work J. Must be a miracle? http://www.whatbird.com/wwwroot/Alice_1.html (works) here is the idea of using (this). http://www.whatbird.com/wwwroot/Alice_2.html (does not work) I just got my copy of Learning jQuery and it's a very good book (took 10 days to get here). Some really basic concepts that got away from me are finally becoming clear. I know enough Javascript, my main issue is not understanding the domain of jQuery and the domain of JS, and how the two differ, but the book is making that clear. Also the book helps me understand that jQuery is really about manipulating elements in the DOM using selectors and traversing the DOM. I think that is where I went astray. I don't think you need to dive deep into JS to grok jQ, but the syntax closeness of the two can be tricky, and not explained well in the tutorials. Like the book spends a lot of time explaining $() which it calls the Factory function. I see now that an object in jQuery does not have a visibility directly, it needs a class assigned to it, so that is why example 2 doesn't work. PS I have read all the tutorials at <http://docs.jquery.com/Tutorials> http://docs.jquery.com/Tutorials and honestly they assume a lot of prior knowledge and leave out some really major lessons for the newbie. PSS I am not sure your metaphor is right, but I agree that the bigger picture needs amplifying on the docs site, and maybe I will end up contributing to that issue, which is not to be critical of the community in any way, you guys are all fabulous and very generous. From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Rob Desbois Sent: Wednesday, July 25, 2007 2:14 AM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Toggling an objects visiblty without show and hide 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] <mailto:[EMAIL PROTECTED]> > wrote: On Jul 25, 12:41 am, "Mitchell Waite" < [EMAIL PROTECTED] <mailto:[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.