Login Register

Add button to div dynamically

I want to create a div dynamically and then create a dijit button and add it to the div.
I keep getting the error Node cannot be inserted at the specified point in the hierarchy" code: "3
Here is the code: What dumb thing am I overlooking?

//create the div
var fdiv= document.createElement("div");
fdiv.dojoType="dojo.dnd.Source";
fdiv.class="container";
fdiv.copyOnly="true";
fdiv.id="src1";
fdiv.jsId="c2";
document.body.appendChild(fdiv);

//create the button
var fparams = { label: "",
id: "but1",
showLabel: false
};

var bt = new dijit.form.Button(fparams, fdiv);
bt.style.top="top";
bt.style.left = fdiv.style.left;
bt.style.height= "40px";
bt.class="dojoDndItem";

//add button to div -- Here it fails with the above error message. What am I doing wrong?
fdiv.appendChild(bt);

Never mind. I found it right

Never mind.
I found it right after I posted it.

James W Cooper

for the benefit of

for the benefit of others:

bt.domNode is the node you would appendChild somewhere.

in Dojo 1.2.0 there is a placeAt method, too:

bt.placeAt(divRefOrStringId);