On Jan 16, 2008 8:10 AM, desbest <[EMAIL PROTECTED]> wrote:
>
> Can someone give me an example of the "replace" feature because the
> prototype documentation is hard to understand.

This would be typical usage...

HTML:

<ul>
  <li id="my-first-item">I have not been replaced, ever!</li>
</ul>

JavaScript:

$('my-first-item').replace('<li id="my-first-item" class="replaced">I
have been replaced!</li>');

What it does it literally swap out one element for another. If you
give replace a string of HTML (as my example does), then it first
creates an element node out of that string, then performs the swap.

It really all boils down to this one line of code, which you can
easily write on your own:

element.parentNode.replaceChild(content, element);

If you look at my previous example, then the object $('my-first-item')
would be the element object in the above snippet and the content
object would be the string of HTML I passed in.

Hope this helps.

-justin

--~--~---------~--~----~------------~-------~--~----~
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 [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-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to