
I call my js function from HTML code from another file. Now I would like to create a input button on page using createElement() in my called function. I used something like this but doesn't seems to work. Lets show is the function being called function show(){ var element=createElement('button'); element.setAttribute('id', 'show'); element.appendChild(document.createTextNode('Button')); } what is the right way

I call my js function from HTML code from another file. Now I would like to create a input button on page using createElement() in my called function. I used something like this but doesn't seems to work. Lets show is the function being called
function show(){
var element=createElement('button');
element.setAttribute('id', 'show');
element.appendChild(document.createTextNode('Button'));
}
what is the right way

<html>
<script>
function addRow(){
var ptable = document.getElementById('ptablePerson');
var lastElement = ptable.rows.length;
var index = lastElement;
var row = ptable.insertRow(lastElement);
var cellText1 = row.insertCell(0);
var element = document.createElement('input');
element.type = 'text';
element.name = 'person' + index;
element.id = 'person' + index;
element.size = 30;
cellText1.appendChild(element);
var cellText2 = row.insertCell(1);
var element = document.createElement('input');
element.type = 'text';
element.name = 'person' + index;
element.id = 'person' + index;
element.size = 30;
cellText2.appendChild(element);
var cellText3 = row.insertCell(2);
var element = document.createElement('input');
element.type = 'button';
element.value='Button';
element.name = 'person' + index;
element.id = 'person' + index;
element.size = 30;
cellText3.appendChild(element);
document.getElementById("psize").value=index;
}
</script>
<form >
<input type="hidden" name="psize" id="psize">
<table style="border:1px solid #000000;" bgcolor="#efefef"
id="ptablePerson" align="center">
<tr>
<td><input type="text" name="person1" id="person1" size="30" /></td>
<td><input type="text" name="person1" id="person2" size="30" /></td>
<td><input type="button" name="person1" value="Button" id="person4" size="30" /></td>
</tr>
</table>
<table align="center">
<tr><td></td><td><input type="button" value="Add" onclick="addRow();" /></td></tr>
</table>
</form>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.