javascript - Jquery Remove Element After Deletion From Server -


i'm working on function deletes images gallery. on php side works. jquery/ajax works. when modified jquery remove element when image gets deleted(remove element client side) no longer works(when no longer works giving me error function built code:

this code works:

function deleteimage(file_name) {     var r = confirm("are sure want delete image?")     if(r == true)     {         $.ajax({           method: "post",           url: '/images/gallery/deleteimage.php',           data: {'delete_file' :  file_name },           success: function (response) {              ohsnap("image has been deleted.", "green");           },           error: function () {              ohsnap("an error has occured.", "red");           }         });     } } 

but 1 doesn't

function deleteimage(file_name) {     var r = confirm("are sure want delete image?")     if(r == true)     {         $.ajax({           method: "post",           url: '/images/gallery/deleteimage.php',           data: {'delete_file' :  file_name },           success: function (response) {              $('#' + file_name).remove();              ohsnap("image has been deleted.", "green");           },           error: function () {              ohsnap("an error has occured.", "red");           }         });     } } 

any idea why adding remove function causing error? in console not telling me why, i'm lost.

update:

here example of 1 of elements:

<div class="thumbimage" id="happy_anime_s2-1433126427.png"> <a href="images/gallery/happy_anime_s2-1433126427.png" data-featherlight="image"> <img src="images/gallery/happy_anime_s2-1433126427.png" width="200px" alt="" /> </a> <span class="deleteimage"> <input type="hidden" value="happy_anime_s2-1433126427.png" name="delete_file" id="delete_file" /> <input type="button" value="delete image" onclick="deleteimage('happy_anime_s2-1433126427.png');"/> </span> </div> 

the problem . in id, creates class selector. looks @ selector #happy_anime_s2-1433126427.png, looks element id happy_anime_s2-1433126427 , has class png.

you need escape . using \\. like

$('#' + file_name.replace('.', '\\.')).remove(); 

selectors

to use of meta-characters ( such !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) literal part of name, must escaped with 2 backslashes: \.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -