Hi,

Leaving aside the question of whether conflating statements on one
line is a good idea, you can do all of it at once like so:

parent.appendChild(new Element('div', {'class': 'container'}));

you can even put text in the element:

parent.appendChild(new Element('div', {'class': 'container'}).update
('Text in element');

HTH,
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 3, 10:07 pm, dwp <dwp-goo...@fourloop.com> wrote:
> Quite often I create large chunks of HTML in javascript and use the
> prototype new Element method. I like this method because you can chain
> it with other methods, and create clean readable code. However, after
> I create an element I usually want to append it to a parent element
> first thing. I can do this in two lines of code with appendChild, but
> that doesn't seem very "prototypish". My solution was to add a
> Element.setParent function. Is there a core method I can use that does
> this better, or is setParent the away to go? I looked at insert, but
> its the other way around parent to child.
>
> Example:
> var divPane          = new Element('div', {'class':'sv_panel' +
> this._className });
> var divContainer    = new Element('div',
> {'class':'container'}).setParent(divPanel);
> var divTitleBar       = new Element('div',
> {'class':'titlebar'}).setParent(divContainer).update("My Titlebar');
> ....
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to