Reputation: 15
I have this button with a div tag
<div class='test'>
<button class="bt1">add statment</button>
</div>
I want to append the div by jquery bellow it the function
$(".test").on("click", ".bt1", function () {
$(".test").append("<p>Statement: <input type='text' name='statement"+ i +"'><br><button class='deleteCon'> Delete</button></p>");
i++;
});
Any one can tell me what is the problem?
Upvotes: 0
Views: 64
Reputation: 1483
I believe you are using append correctly but it appears that i
was not defined.
See the following javascript:
var i = 0;
$('.bt1').on('click', function() {
$('.test').append("<p>Statement: <input type='text' name='statement"+ i +"'><br><button class='deleteCon'> Delete</button></p>");
i++;
});
Upvotes: 0
Reputation: 4076
Your problem is that i
is not declare on the scope:
var i = 1; //Declare
$(".test").on("click", ".bt1", function () {
$(".test").append("<p>Statement: <input type='text' name='statement"+ i +"'><br><button class='deleteCon'> Delete</button></p>"); i++; });
Upvotes: 1