I notice that if I intend to add class to an element that I must use
className and not class for my object.  But what if I intend to name
my element?  What do you use then?  For example:

{ className : "foo", innerHTML : "bar" }

On a newly defined TD yields:
<td class="foo">bar</td>

But if the object is:
{ name="somename", className : "foo", innerHTML : " }
The attribute name *does not appear* on my new TD element.
Originally, I was doing this:

{ class : "foo", innerHTML : "bar" }

And was never getting class on my TD object.  So how do you know which
names to use in order to get the result on the element you desire?

Thanks,
Karl..

On Aug 31, 11:20 am, kstubs <kst...@gmail.com> wrote:
> Thanks Richard for your answer on this!  Question regarding this:
>
> > Object.extend(..., options || {}) // Extend the object created about
>
> Is it necessary to || {} (empty object) so as to not break the
> Object.extend in the event that options is null?
>
> Karl..
>
> On Aug 31, 10:19 am, Richard Quadling <rquadl...@gmail.com> wrote:
>
>
>
> > On 31 August 2010 17:49, kstubs <kst...@gmail.com> wrote:
>
> > > Hello,
> > > Full credit to: Matthew Foster for the code below.  I'd like an
> > > explanation of the below.  I'm having some troubles with Object extend
> > > and would like a better explanation of the magic that occurs below.
>
> > > $C = function(name, options) {
> > >    return Element.extend(Object.extend(document.createElement(name ||
> > > "div"), options || {}));
> > > }
>
> > > Sample use:
> > > var next = $C("td", { innerHTML: "&gt;", className: "next" });
>
> > > So how are the properties innerHTML and className morphed on to this
> > > new td element?
>
> > > Thanks,
> > > Karl..
>
> > Object.extend takes a set of name/value pairs and applies them to
> > whatever object it is extending.
>
> > So, innerHTML and className, both properties of the DOM element TD,
> > get assigned by Object.extend.
>
> > Taking the code inside out ...
>
> > document.createElement(name || "div") // Create an element based of
> > the type defined by the value of name or a div, if no name is
> > supplied.
> > Object.extend(..., options || {}) // Extend the object created about
> > with the name/value pairs in options, or not, if no options have been
> > supplied.
> > Element.extend(...) // Same as $(...);
>
> > Hope that helps.
>
> > --
> > Richard Quadling
> > Twitter : EE : Zend
> > @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
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-scriptacul...@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