I''ve just started using prototype and its been ages since I wrote javascript, and I am a little confused by the syntax. From the online doc I understand that, for example, I can get the value of the style ''visibility'' like this: <div id="someDiv"></div> var yy = $(''someDiv'').getStyle( ''visibility'' ); Based on another post I tried: var yy = $($(''someDiv'')).getStyle( ''visibility'' ); but that didnt work either. (These give me "... is not a function" errors in Firebug. What does work is: var yy = Element.getStyle( $(''fade''), ''visibility'' ); which I got by reading the code. That''s fine, but I would sure prefer the shorthand method especially as what I am beginning will be fairly complex. I am using both Firefox 2.whateverislatest and IE6, by the way. Could someone offer me a quick clue and perhaps point me to some good reading to get back up to speed? Thanks in advance, Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 jan, 21:15, "Mike L." <michael.livings...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve just started using prototype and its been ages since I wrote > javascript, and I am a little confused by the syntax. > > From the online doc I understand that, for example, I can get the > value of the style ''visibility'' like this: > > <div id="someDiv"></div> > > var yy = $(''someDiv'').getStyle( ''visibility'' ); > > Based on another post I tried: > > var yy = $($(''someDiv'')).getStyle( ''visibility'' ); >What are you trying to accomplish using this? the dollar function... $ () ... is just shorthand for document.getElementById() and extending the element with all the prototype methods while you''re at it. So what you''re trying to do there is something like this: var yy document.getElementById(document.getElementById(''someDiv'')).getStyle(''visibility''); Now that doesn''t really make sense, does it? What you probably saw was the $$() function... that function takes a css-selector as parameter and finds elements with that: var yy = $$(''div#someDiv''); In your case it doesn''t really make sense to use the $$ function as that returns a collection of elements, not just one. If you do expect to get multiple results you can do something like this: $$(''div.someClass'').invoke(''getStyle'', ''visibility''); Oh.... and if you''re just trying to get the visibility to do something if it is visible/invisible you might want to look at the method Element.visible(). This returns true or false and checks not only for visibility, but also for opacity and display.> but that didnt work either. (These give me "... is not a function" > errors in Firebug. What does work is: > > var yy = Element.getStyle( $(''fade''), ''visibility'' ); > > which I got by reading the code. That''s fine, but I would sure prefer > the shorthand method especially as what I am beginning will be fairly > complex. I am using both Firefox 2.whateverislatest and IE6, by the > way. > > Could someone offer me a quick clue and perhaps point me to some good > reading to get back up to speed? > > Thanks in advance, > > Mike--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply Wizz. You gave me the clues I was looking for. This example was not meant to be something specific I am trying to solve, just a way to get a grip on the proper syntax. It has literally been years since I have written javascript and a lot has changed, not the least of which is the availability of frameworks like prototype. I tried to use the documentation at face value but clearly it is not meant to work that way, or at least my understanding of what it is saying needs to improve. Can you suggest somewhere I can get a quick and general description of how to manipulate a webpage as a good place to build from? M On Jan 24, 3:45 pm, Wizz <woutaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 jan, 21:15, "Mike L." <michael.livings...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve just started using prototype and its been ages since I wrote > > javascript, and I am a little confused by the syntax. > > > From the online doc I understand that, for example, I can get the > > value of the style ''visibility'' like this: > > > <div id="someDiv"></div> > > > var yy = $(''someDiv'').getStyle( ''visibility'' ); > > > Based on another post I tried: > > > var yy = $($(''someDiv'')).getStyle( ''visibility'' ); > > What are you trying to accomplish using this? the dollar function... $ > () ... is just shorthand for document.getElementById() and extending > the element with all the prototype methods while you''re at it. So what > you''re trying to do there is something like this: > > var yy > document.getElementById(document.getElementById(''someDiv'')).getStyle(''visibility''); > > Now that doesn''t really make sense, does it? > What you probably saw was the $$() function... that function takes a > css-selector as parameter and finds elements with that: > > var yy = $$(''div#someDiv''); > > In your case it doesn''t really make sense to use the $$ function as > that returns a collection of elements, not just one. > > If you do expect to get multiple results you can do something like > this: > > $$(''div.someClass'').invoke(''getStyle'', ''visibility''); > > Oh.... and if you''re just trying to get the visibility to do something > if it is visible/invisible you might want to look at the method > Element.visible(). This returns true or false and checks not only for > visibility, but also for opacity and display. > > > but that didnt work either. (These give me "... is not a function" > > errors in Firebug. What does work is: > > > var yy = Element.getStyle( $(''fade''), ''visibility'' ); > > > which I got by reading the code. That''s fine, but I would sure prefer > > the shorthand method especially as what I am beginning will be fairly > > complex. I am using both Firefox 2.whateverislatest and IE6, by the > > way. > > > Could someone offer me a quick clue and perhaps point me to some good > > reading to get back up to speed? > > > Thanks in advance, > > > Mike--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---