Moti Mashiah
asked on
Jquery
Hi Guys,
I have some issue with removing images after I add them through jquery.
Here is my example:
I have this div:
and here is my code for delete image which is not working:
The issue I have here is when I delete the image at the div and then add new one I can't delete the image again.
I can only delete the images I didn't create through jquery.
I have some issue with removing images after I add them through jquery.
Here is my example:
I have this div:
<div id="imgshow1" class="col-sm-3 col-md-3 form-group">
<div class="img-wrapi">
<span class="close">×</span>
<img src="~/pics/no_image.gif" width="150" height="150" id="pic1" />
</div>
</div>
Here is my jQuery..see how I add image:$("#imgshow1").html('<div class="img-wrapi"><span class="close">×</span><img src="/pics/' + data + '" width="150" height="150"/></div>')
and here is my code for delete image which is not working:
$('.img-wrapi .close').on('click', function () {
debugger;
var id = $(this).closest('.img-wrapi').find('img').attr('id');
if (id == "pic1") {
var test = $("#pic1").remove();
}
The issue I have here is when I delete the image at the div and then add new one I can't delete the image again.
I can only delete the images I didn't create through jquery.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep, I'm aware about that one.
The issue is that when I delete the image then add image the function even doesn't run
like this one:
$('.img-wrapi .close').on('click', function () {
The issue is that when I delete the image then add image the function even doesn't run
like this one:
$('.img-wrapi .close').on('click', function () {
ASKER
HI Julian,
I will try your solution now.
Please, can you tell me if you have any better idea other then check id ?
I will try your solution now.
Please, can you tell me if you have any better idea other then check id ?
ASKER
Julian, your solution is working thank you soo much.
Just one more thing. can you advise how can I delete by avoiding check the id.
thanks,
Just one more thing. can you advise how can I delete by avoiding check the id.
thanks,
ASKER
Thank you Julian.
You are welcome
Just one more thing. can you advise how can I delete by avoiding check the id.Did you answer this one?
Open in new window
The above would now delete the created picture through your function.