Dynamically Creating Buttons In JavaScript

I found something interesting when dynamically creating a button in JavaScript.  If I coded the button like the following:

var button = document.createElement("INPUT");
button.type = "button";
parent.appendChild(button);
button.value = "Click Me";

This worked fine, but if I reversed it to this:

var button = document.createElement("INPUT");
parent.appendChild(button);
button.type = "button";
button.value = "Click Me";

This did work, an HTML file error.  Interesting.

Published Tuesday, October 07, 2008 6:21 PM by bmains
Filed under: ,

Comments

No Comments