On Jan 13, 2011, at 10:27 AM, Mauro wrote:
Or is something else confusing you?
It's not clear to me how put data in the DOM and how to read.
Sorry for my ignorance.
Whenever you have Rails create HTML content and serve it to the
browser (i.e., pretty much all the time) you are putting that content
into the DOM (Document Object Model) of the browser. Now if you place
some content above the visible page using CSS, or simply set it to
display:none, it will still be in the DOM, but it will be hiding and
waiting for you to do something with it subsequently using JavaScript.
In Prototype, you most easily access a single HTML element (like a
DIV) using the $('theIdOfTheElement') shortcut for the native JS
getElementById(id) construct.
If you want to access a collection of elements that have the same tag
name or classname or some other common denominator, you use $$
('div.foo') or similar. That gets you an enumerable collection, which
you iterate using each(), just like in Ruby.
If you want to grab the content of a DIV, or show it from its hidden
state, or make it bound around the window like a terrified mountain
goat, you can do that once it's in the DOM.
You can also access content from your server using an Ajax call, and
either directly replace any element in the page, or use that content
as variable data to further modify your page.
I believe that jQuery is similar to Prototype in syntax and
construction. You may find an easier path to answers by looking up the
library documentation on their very glossy site.
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.