Unfortunately my code does work J. Must be a miracle?
The one where you used 'this' instead of 'cheshireCat' didn't work - that was the one I was referring to. My last post clears that up a bit more understandably I hope.
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.
Excellent - good luck with it!
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.
Ok, I hope my post didn't offend in any way. Re-reading your posts, I think your conclusion is correct - understanding what is jQuery and what is JS, and the differences, can be tricky. I'm not so sure about not needing a good understanding of JS - really getting to grips with relatively advanced topics like closures is quite important IMO - I certainly struggled with some bits of JS I'd never seen before coming to jQuery, especially when extending jQuery yourself.
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.
Not entirely sure what you mean by this..?
PS I have read all the tutorials at 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.
In what sort of areas do you think too much is assumed in the tutorials? I'm not so sure about the metaphor - jQuery is a tool, the use of which requires knowledge and understanding of how you use that tool, as with anything. I would strongly advise anyone wanting to use jQuery to learn JavaScript first, but that is my opinion - you think otherwise, perhaps the rest of the community would disagree with me too ;-) In terms of adding to the docs I'm sure nobody will be offended. We all approach learning a new language / tool / platform in different ways, if you found that the existing reference and tutorials were not sufficient or appropriate for you then there are probably others in a similar situation. By going through the hard part and contributing yourself, you add your own viewpoint which might be just what someone else needs, which can only be a good thing. --rob *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] > 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.
-- 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.