У меня есть форма, и я могу динамически добавлять больше строк, но если я попытаюсь удалить определенную строку, это не сработает, однако первая строка удаляется без проблем.jQuery удалить выбранный элемент, динамически сгенерированный
Вот HTML:
<form class="order-form">
<div class="product-lines">
<!-- Product Line Section -->
<div class="product-line">
<a href="#" alt="close" class="btn-close" title="Remove"><img alt="remove" src="img/close.png" /></a>
<input class="input-text" name="product-code" type="text" placeholder="Product Code" ></input>
<input class="input-text" name="product-quantity" type="text" placeholder="Quantity"></input>
<input class="input-text" name="product-discript" type="text" placeholder="Discription of Product"></input>
<label class="label-sign">£</label>
<input class="input-text" name="product-price" type="text" placeholder="RRP Price"></input>
<br>
</div>
</div>
<div id="product-btn">
<input name="btn-add-line" type="button" value="Add new line"></input>
<input name="btn-update" type="button" value="Update"></input>
<input name="btn-submit" type="submit" value="Submit Order"></input>
<label class="label-sign">£</label>
<input class="input-text" name="order-info" type="text" placeholder="Order total" ></input>
</div>
</form>
код JQuery Я пробовал:
$(".btn-close").on("click", function(e){
$(e.currentTarget).parent().remove();
});
Я также попытался
$(e.currentTarget).parents("div.product-lines).next("div.product-line).remove();
Любая помощь будет самой высокой оценки, а также объяснение было бы очень полезно для меня, чтобы учиться.
http://learn.jquery.com/events/event-delegation/ - so '$ (document) .on ('click', '.btn-close', function() {...})' –