DOM Scripting Javascript, set element value -
I aim to add a button to the screen through the click of any other button. I can successfully add them, but they are empty (i.e., no text).
I tried to determine the value with this technique:
addButton.setAttribute ("value" "click me"); It has been unsuccessful, the odd thing is that I was able to set the element ID successfully with the set attribute function.
Then I tried the following:
var x = document.getElementById ("buttonId"); x.value = "click me"; The above button did not have to be added at all.
Maybe I'm missing something but I do not think why the first method will not work.
Note: All of these buttons have been made to fly so that the standard:
& lt; Input type = "button" value = "click me" /> will not be enough.
Any help appreciated.
addButton function (elementId, value, name, type) {// an input type dynamic Create form var element = document.createElement ("Input"); // element to different attributes element.type = type; Element.value = value; // Actually? Do you want the default value to be typed? Element.name = name; // More names too? Var foo = document.getElementById (elementId); // Adding element to page (in period) foo.appendChild (element); } Try it out.
Example Bella:
Comments
Post a Comment