Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<html>
<head>
    <script type="text/javascript">
      var instance = 4;
    function newTextBox(element) {                
        instance++; 
        var newInput = document.createElement("input"); 
        newInput.id = "text" + instance; 
        newInput.name = "text" + instance; 
        newInput.type = "text"; 
        var div = document.createElement('div'); 
        div.appendChild(newInput); 
        document.body.insertBefore(div, element); 
    } 
    </script>
</head>
<body>
        <input id="text2" type="text" name="text1"/> <br>
        <input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
</body>
 
if (document.getElementById('hello')) {
  document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript';
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers