troubleshooting Question


Avatar of Moti Mashiah
Moti MashiahFlag for Canada asked on
JavaScriptjQuery* div
7 Comments1 Solution137 ViewsLast Modified:
Hi Guys,

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">&times;</span>
                                                <img src="~/pics/no_image.gif" width="150" height="150" id="pic1" />
Here is my jQuery..see how I add image:
$("#imgshow1").html('<div class="img-wrapi"><span class="close">&times;</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 () {
        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.
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros