All of insert/update/replace can take several kind of arguments:
- A string of HTML (how Prototype worked up until 1.5.2)
- An Element (either something you build with new Element or something
you get from the dom -- ie, $("something"))
- An object that responds to "toElement", which should return an Element object.
- An object that responds to "toHTML", which should return a string of HTML.
So for example:
var Person = Class.create({
initialize: function(name) {
this.name = name;
},
toElement: function() {
return new Element("li", { className: "person" }).update(this.name);
}
});
var john = new Person("John");
$("people").insert(john);
Should work fine :)
Best,
-Nicolas
On Dec 7, 2007 10:17 AM, LexNonScripta <[EMAIL PROTECTED]> wrote:
>
> As I was combing through the API yesterday, I saw a HUGE surprise
>
> ELEMENT IS A CONSTRUCTOR!! HIP HIP - HOOORAY!
>
> Just what we needed!
>
> Now, there was something I didn't understand. Can you append a newly
> created html element
> // fancy_input = new Element('input', {yada:'yada'... }) //
> to an existing element
> // $('my_test_form_thingie').insert( bottom: fancy_input ); //
> (is element.appendChild() called internally)
>
>
> Also, can I chain stuff like this:
> [A] $('my_test_form_thingie').insert( bottom: fancy_input, bottom:
> '<br /> This thing I inserted above is a fancy input. Prototype I love
> you. Marry me!' );
>
> OR must I use
>
> [B] $('my_test_form_thingie').insert( bottom:
> fancy_input).insert(bottom: '<br /> This thing I inserted above is a
> fancy input. I like chaining.. boohoo.. :(' );
>
>
> Cheers!
>
>
> On Dec 6, 4:17 pm, themire <[EMAIL PROTECTED]> wrote:
> > Agreed. They don't explain what keywords to use for at the top, etc.
> >
> > On Nov 21, 12:17 pm, LexNonScripta <[EMAIL PROTECTED]> wrote:
> >
> > > I must say that I was quite surprised to see the Prototype
> > > documentation being so unclear about theElement.insertfunction
> > > (http://www.prototypejs.org/api/element/insert).
> >
> > > I tried testing it, but I could not make any sense of it. Where does
> > > the "position" of theinsertgo as an argument.
> >
> > > I would really appreciate a clear example.
> >
> > > Tnx,
> >
> > > DizyArt
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---