0

How do I do, that when user click button, appeared another string with <Input>?

And ID of Input will be grow.

I want something like this:

<button id="add">add</button>
<input id="e-1" type="text">
<input id="e-2" type="text">
....

No php please.. I'd prefer JQuery

2 Answers 2

1

Demo

This'll do it

HTML

<button id="add">add</button>
<div id="inputs"></div>

jQuery

var i = 0;
$("#add").click(function(){
    $("#inputs").append('<input id="e-'+(++i)+'" type="text"><br>');
});
Sign up to request clarification or add additional context in comments.

Comments

0
<div>
    <button class="container-add-input"></button>
    <input type='text' />
    <input type='text' />
</div>
<script type="text/javascript">
    $(".container-add-input").click(function() {
        $(this).parent().append("<input type='text' />");
    });
</script>

1 Comment

I like the parent append idea, but you forgot the incremental id's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.