Skip to main content
1 de 4
Bender Paisa
  • 12.5k
  • 4
  • 28
  • 42

Si usas la librería jQuery de javaScript lo podrías hacer de esta sencilla forma:

$(document).ready(function() {
    $("#add_email").click(function(){
        $(this).before('<div><label for="email">email:</label><input type="email" id="email" /></div>');
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form action="page.php" method="post">
    <div>
        <label for="name">Name:</label>
        <input type="text" id="name" />
    </div>

    <div>
        <label for="email">email:</label>
        <input type="email" id="email" />
    </div>
    <div class="button">
        <button type="button" id="add_email">add</button>
    </div>

    <div>
        <label for="msg">Message:</label>
        <textarea id="msg"></textarea>
    </div>

    <div class="button">
        <button type="submit">Send your message</button>
    </div>
</form>

Bender Paisa
  • 12.5k
  • 4
  • 28
  • 42