PDA

View Full Version : Dynamically add an Element to the DOM



RooSoft
14 May 2010, 6:06 AM
Simple question... How can I add this button to the DOM dynamically? To put you in context, I have to do this in a JS event which is triggered by Google Maps API.



var button = new Ext.Button({
id: 'myButton',
text: 'Click me!'
});

Ext.getDoc().appendChild(button);


When I execute this, I get this error:

a(d) is null


Thanks for any help!

Marc Lacoursière
RooSoft Computing inc.

Animal
14 May 2010, 6:12 AM
IF (and it's a big IF), you must just put Ext Components into the DOM, you render them.

An Ext Component is not an Element. It is an Object under the base class Ext.Component. It has an Element once it is rendered.

RooSoft
14 May 2010, 6:15 AM
Thanks Animal! It's very helpful!

To be honnest, I am not trying to render a button, but a context menu using a Ext.menu.Menu when I right click something in a Google Map.

Can you point me to the cleanest way to do this? Do I have to explicitly render it by hand?