Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am working on MVC 5,

After remove the image from folder, the div contain image is now removing.

JavaScript
$(document).on("click", ".deleteProImg", function (e) {
    debugger
    if (confirm("Are you sure you want to delete?")) {       

        var imgId = $(this).attr('id');
        var _imgId = imgId.substring(10);       
        $.ajax({
            url: '/Product/DeleteProImage/',
            type: "POST",
            data: { proFileName: _imgId },
            success: function (data) {
                $('#' + _imgId).remove();
            }
        });
    }
    return false;
});


What I have tried:

View,

HTML
<div id="uploadedImages">
        <div id="25cb10a7-3ae0-41a7-9b40-964ea0e74308.png"><img id="undefined" src="../Product/Image?imageName=25cb10a7-3ae0-41a7-9b40-964ea0e74308.png" width="135" height="135"> <button class="deleteProImg" id="btnProImg_25cb10a7-3ae0-41a7-9b40-964ea0e74308.png">Delete</button> <input type="hidden" value="25cb10a7-3ae0-41a7-9b40-964ea0e74308.png" name="img_81"></div></div>


How can I remove the $('#25cb10a7-3ae0-41a7-9b40-964ea0e74308.png') div ?
Posted
Updated 2-May-17 3:07am
Comments
ZurdoDev 2-May-17 6:49am    
$("#divID").remove()
Member 12955507 2-May-17 6:52am    
yes I did tried. $('#' + _imgId).remove(); here _imgId = "25cb10a7-3ae0-41a7-9b40-964ea0e74308.png" but not happening.
ZurdoDev 2-May-17 6:56am    
Then debug it. You'll need to make sure $("#25cb10a7-3ae0-41a7-9b40-964ea0e74308.png").length > 0.
Member 12955507 2-May-17 6:59am    
yes, I did debug then _imgId = "25cb10a7-3ae0-41a7-9b40-964ea0e74308.png". but still the div is not removing.
ZurdoDev 2-May-17 7:04am    
And what is $("#25cb10a7-3ae0-41a7-9b40-964ea0e74308.png").length ?

1 solution

When ever we are creating any dynamic id for HTML control we should follow some rules.
Once your id is correct then your jquery will work fine.

Please refer this link, it may help you.

What are valid values for the id attribute in HTML? - Stack Overflow[^]
 
Share this answer
 
Comments
Nirliptananda 9-Jun-17 11:18am    
Thanks Buddy !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900