Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]

You may face this error when you add a Dojo component to a normal DOM element using appendChild as follows:

<div id="container"></div>

<script type="text/javascript">
	dojo.addOnLoad(function(){
		var dojoInputField = new dijit.form.TextBox({id: "txtName"});
		document.getElementById("container").appendChild(dojoInputField);
	});
</script>

This error appears because you try to add the Dojo element itself not the DOM node that it wraps. In order to fix this issue, you can do this by adding the component DOM node as follows:

<div id="container"></div>

<script type="text/javascript">
	dojo.addOnLoad(function(){
		var dojoInputField = new dijit.form.TextBox({id: "txtName"});
		document.getElementById("container").appendChild(dojoInputField.domNode);
	});
</script>	
This entry was posted in Dojo, JavaScript, Web 2.0 and tagged , , , by Hazem Saleh. Bookmark the permalink.

About Hazem Saleh

Hazem Saleh has more than eleven years of experience in Cloud, Mobile and Open Source technologies. He worked as a software engineer, technical leader, application architect, and technical consultant for many clients around the world. He is an Apache PMC (Project Management Committee) member and a person who spent many years of his life writing open source software. Beside being the author of the "JavaScript Unit Testing" book, "JavaScript Mobile Application Development" book, "Pro JSF and HTML5" book and the co-author of the "Definitive guide to Apache MyFaces" book, Hazem is also an author of many technical articles, a developerWorks contributing author and a technical speaker in both local and international conferences such as ApacheCon North America, Geecon, JavaLand, JSFDays, CON-FESS Vienna and JavaOne. Hazem is an XIBMer, he worked in IBM for ten years. Now, He is working for Nickelodeon New York as a Mobile Architect. He is also an OpenGroup Master Certified Specialist.