ians ians - 2 months ago 21
Javascript Question

Dojo Query returns undefined

I am trying to get a DOM element by class and not sure why its returning undefined. I can query the parent element without any problems. Here is my code:

var contentPane = query('.contentPane', this.map.infoWindow.domNode)[0];
var header = query('.header', this.map.infoWindow.domNode)[0];

console.log(header);
console.log(contentPane);


The output in console:

>>undefined

<div class="contentPane">
<div class="esriViewPopup" id="esri_dijit__PopupRenderer_1" widgetid="esri_dijit__PopupRenderer_1">
<div class="mainSection">
<div class="header" dojoattachpoint="_title"></div>
<div class="hzLine"></div>
<div dojoattachpoint="_description"></div>
<div class="break"></div>
</div>
<div class="attachmentsSection hidden">
</div>
<div class="mediaSection hidden">
</div>
<div class="editSummarySection hidden" dojoattachpoint="_editSummarySection">
</div>
</div>
</div>

Answer

the .header was not rendered at the time of query. I have resolved this by using query when the containing function was completed.