Travis wrote:
> I'm having some problems with a class I am creating. My end goal is
> to be able to instantiate a class and use its return value as a
> particular object.
>
> So far, here's my code:
>
> SomeDiv = Class.create ({...});
>
> Event.observe(window, 'load', function() {
> $('otherDiv').appendChild(new SomeDiv());
> });
>
> Firebug says: "Node cannot be inserted at the specified point in the
> hierarchy" so my guess is that it is not creating the div object. Any
> suggestions? Thanks!
Travis,
Not sure exactly what functionality you're trying to achieve, but using
the "new" keyword will always return an object of that instance.
Element#appendChild requires that the argument given be a DOM Element.
You'll need to do something along these lines:
SomeDiv = Class.create({
initialize: function(msgNode) {
this.node = new Element("div");
this.msg = $(msgNode);
// add some custom method to our node
this.node.manipulate = this.manipulate.bind(this);
// garbage collect
Event.observe(window, 'unload', function() {
this.node.manipulate = null;
}.bind(this));
},
manipulate: function(style, html) {
// do stuff to the node
this.node.setStyle(style);
this.node.update(html);
this.msg.update('manipulated');
}
});
Event.observe(window, 'load', function() {
$('otherDiv').appendChild(new SomeDiv().node);
});
- Ken Snyder
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---