Reputation: 1109
I am developing an app where someone can select multiple Images from a gallery. I've appended a button with every image which calls the function onclick. How can I remove the image appended with button onclick ?
<div id="images">
<img src="www.xyz.com/qwert.jpg" class="hi">
<input type="button" class="multiple">
<img src="www.xyz.com/qwerty.jpg" class="hi">
<input type="button" class="multiple">
<img src="www.xyz.com/qwertww.jpg" class="hi">
<input type="button" class="multiple">
</div>
Upvotes: 0
Views: 1886
Reputation: 167172
You can use this code:
$(".multiple").click(function () {
$(this).prev("img").remove();
});
Snippet
$(function () {
$(".multiple").click(function () {
$(this).prev("img").remove();
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="images">
<img src="www.xyz.com/qwert.jpg" class="hi">
<input type="button" class="multiple">
<img src="www.xyz.com/qwerty.jpg" class="hi">
<input type="button" class="multiple">
<img src="www.xyz.com/qwertww.jpg" class="hi">
<input type="button" class="multiple">
</div>
Upvotes: 2