From function to object constructor - problem [solved]
Hinfriends ! in JS, i wrote a function to add a button and it works perfectly. Now, as i need more button, i would like to transform this function to an object constructor but it doesn't work (button isn't displayed). can you help me and see what is wrong : this fuction works good: command(); function command(){ var btn = document.createElement("button"); var btnText = document.createTextNode("Go!"); btn.appendChild(btnText); document.getElementById("startPage").appendChild(btn); btn.setAttribute("id","buttonGo"); } the object constructor = problem : buttonGo = new command("Go!","buttonGo"); function command(text,idName){ this.text = text; this.idName = idName; this.commandCreate = function(){ var btn = document.createElement("button"); var btnText = document.createTextNode(text); btn.appendChild(btnText); document.getElementById("startPage").appendChild(btn); btn.setAttribute("id",idName); }; Many thanks !