Reputation: 859
usage domconstruct = http://dojotoolkit.org/reference-guide/1.9/dojo/dom-construct.html#dojo-dom-construct-place
the second argument of place() is
refNode String|DomNode The DOM node where the node should be placed. If a string, it is assumed to be the ID of the node
It says I can use DOM nodes, so I tried to get the domnode with jquery -> error Also tried it with Dojo's query() -> same error
The error:
Uncaught TypeError: Object [object Object] has no method 'appendChild'
My code domConstruct.place(errorBoxHtml, $("#"+currentView.id+" .content") , "first");
Upvotes: 0
Views: 1303
Reputation: 44745
dojo/query
and jQuery's selectors are not returning proper DOM nodes, but are returning a list of nodes.
You can see an example using jQuery on this JSFiddle. As you can see in the console, it says "No it isn't"
, which means it isn't returning the DOM node of the selector you wrote, you can even see in the console what it actually returns (an array of DOM nodes).
I also made the same example using Dojo in this JSFiddle. As you can see there, dojo/query
doesn't return a DOM node either but a list of DOM nodes. However, when you use the dojo/dom
module and the method byId()
you will get a DOM node as a result.
This explains why your code doesn't work. If you're using a query, you can use dojo/NodeList-dom
to get all nodes independently and call the function on each node, or if you're sure there's only 1 DOM node, you can also use:
require(["dojo/query", "dojo/domReady!"], function(query) {
var myNode = query("...")[0];
});
But then I think something is wrong with the modules you're using. A query is used to retrieve zero to many results and you should use it that way. If you want to get a specific DOM node you should identify it by using ID's and use the dojo/dom
module since it's made for that purpose.
Upvotes: 1
Reputation: 859
If I had the id, I would be able to type the id as a string in the function. That works fine. My div just had a classname, but I gave them all an id. Now I can just use the id as a string as 'refNode' argument in the function
Upvotes: 0
Reputation: 547
I think there is a chance that you are not getting a proper domNode (as Dojo understand it). Why don't you use the dojo.byId API to get it?
Upvotes: 0