erotavlas
erotavlas

Reputation: 4483

Error using built version of Dojo (but not the uncompressed source)

I noticed something weird when using the uncompressed source of Dojo our code runs normally without error. I tried these two from the archives so far

dojo-release-1.10.6-src and dojo-release-1.10.8-src

However when I switch to the built versions, either

dojo-release-1.10.6 or dojo-release-1.10.8

There is an error that occurs when using dojo.query

TypeError: root.getElementsByTagName is not a function

My function call looks like this

var dom_frag = domConstruct.toDom(response);
var title = dojo.query(".accordion_title", dom_frag)[0];

where response contains HTML string. (too long to post here)

EDIT: Image of debugger showing contents of 'dom_frag'

enter image description here

enter image description here

Upvotes: 1

Views: 86

Answers (2)

Dan Piccolo
Dan Piccolo

Reputation: 94

Ok, have you checked to see if the dom_frag variable is a single dom node? If the dom fragment is multiple nodes, then the dojo.query won't work, because it needs to search the children of a single dom node. To solve this, try wrapping the toDom contents with a single node... like so:

var dom_frag = domConstruct.toDom("<div>"+response+"</div>");
var title = dojo.query(".accordion_title", dom_frag)[0];

This is, of course, a bit of a hack... but if you can't guarantee that the response will end up a single node, then you need to do it.

Upvotes: 2

GibboK
GibboK

Reputation: 73918

Make sure your root is actually a DOM element as:

the Element.getElementsByTagName() method returns a live HTMLCollection of elements with the given tag name. The subtree underneath the specified element is searched, excluding the element itself. Ref.

Upvotes: 0

Related Questions