-
26 Nov 2009 3:53 AM #1
Problems with Element.appendChild and Element.appendTo
Problems with Element.appendChild and Element.appendTo
Hello,
i have some problems with Element.appendChild and Element.appendTo:
I have a simple html page (with an empty body) and the following JS code:
Could anyone make some light here?Ext.onReady(function(){
console.log("ready");
var el = new Ext.Element("<div>hello</div>");
var b = Ext.getBody();
//the following doesn't work
b.appendChild(el);
//I also tried - also doesn't work
el.appendTo(b);
})
Thank you.
-
26 Nov 2009 8:33 AM #2
The constructor for Ext.Element is a string (an elementId), not a markup fragment.
Review the API Docs, for Ext.Element a bit closer:
Code:Ext.onReady(function(){ console.log("ready"); var b = Ext.getBody(); //raw markup var div = b.insertHTML('afterBegin', "<div>hello</div>", true); //or DomHelper config var div = b.createChild({ tag: 'DIV', html: 'hello' }); });"be dom-ready..."
Doug Hendricks
Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.
Got Sencha licensing questions? Find out more here.
-
27 Nov 2009 12:47 AM #3
Thanks a lot!
The documentation seemed to me a bit misleading on this topic, but with your point now it seems clearer.
Yet, if this is the case (and it is) it means the following are the same:
And I see no real point for this.Code:new Ext.Element('header'); Ext.Element.get('header');
I have also looked for a way to get the html of an element (not the innerHTML). Is there a way?
-
27 Nov 2009 4:07 PM #4
@radubrehar --
all return the same Ext.Element.instance, just different routes (and reasons).Code:var el = new Ext.Element('header'); var el = Ext.Element.get('header'); var el = Ext.get('header');
Regarding the markup for a DOM element:
IE is the only that supports outerHTML. In order to get that from other browsers, you'd have to clone the node in question, and insert THAT into a bogus DIV Element and take its innerHTML.
Is there a compelling reason that you need the inclusive markup text for a DOM Element?"be dom-ready..."
Doug Hendricks
Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.
Got Sencha licensing questions? Find out more here.


Reply With Quote


