View Full Version : document.getElementById returns null

23 Apr 2013, 5:53 AM

So I have a panel, with another panel inside it, and this other panel contains this :

html: '<div id="foo">...</div>'

In the initComponent function of the first panel, I'd like to get the html element with document.getElementById('foo') or Ext.get('foo'), but it returns null.

What am I doing wrong ?


I guess it's because the html is not loaded yet in the initComponent function. Is there a function that gets called after the component is loaded ?

23 Apr 2013, 6:38 AM
As you mentioned, when the initComponent function is executed, the panel has not been rendered to the DOM yet, so the div that you are trying to reference doesn't exist. You will have to wait until the component is actually rendered to the DOM.

You could add an afterrender listener to your panel and then execute your code then.


23 Apr 2013, 11:55 PM
Thanks droessner.