My confirm dialog is not working as I wanted
Hi, Im trying to delete my images using jquery ajax and php.
And I already have everything working fine, but now Im trying to do a confirmation message in a dialog, and if user clicks on "yes" I do my delete and if user clicks in "no" I close my dialog.
But Im having some difficults with my jQuery, when I click on my delete link Im opening my dialog, its ok, but my when I click in my "no" I dont close my dialog.
And also When I click in yes, I want to remove but I also want to close my dialog but its not working correctly.
Do you see what Im doing wrong?
So I have my dialog:
- <div class="delete_dialog">
- <div class="delete">
- <p>Are you sure you want to remove this image?</p>
- <a href="#" id="delete">Yes</a>
- <a href="#" id="toggleDialog">No</a>
- </div>
- </div>
And my html for my gallery:
- <div class="galery">
- <?php
- echo '<ul>';
- while ($result = $read->fetch(PDO::FETCH_ASSOC)){
- echo '<li id="'.$result['id'].'">';
- echo '<img src="'.$result['img'].' />';
- echo '<a href="#" id="'.$result['id'].'" class="galerydel">Delete</a>';
- echo '</li>';
- }
- echo '</ul>';
- }
- ?>
- </div><!--/gallery-->
And my jquery:
- var url = 'delImages.php';
- $('.galerry ul').on('click','.galerrydel',function(){
- var delid = $(this).attr('id');
- $('.delete_dialog').fadeIn("slow",function(){
- ('.delete').fadeIn("slow");
- });
- $("a#delete").click(function(){
- $('.galerry ul li[id="'+ delid +'"]').css('background','red');
- $.post(url,{actin:'del_imgl',image:delid},function(){
- window.setTimeout(function(){
- $('.galerry ul li[id="'+ delid +'"]').fadeOut("slow");
- },500);
- $('.delete').fadeOut("fast",function(){
- $('.delete_dialog').fadeOut("fast");
- });
- });
- $("a#toggleDialog").click(function(){
- $('.delete').fadeOut("fast",function(){
- $('.delete_dialog').fadeOut("fast");
- });
- });
- });
- return false;
- })
And then my css:
- .delete_dialog{display:none;position:fixed; left:0px; top:0px; width:100%; height:100%; background:rgba(0,0,0,0.5); z-index:104;}
- .delete_dialog .delete{padding:30px; width:260px; text-align:center; background:#fff; position:absolute; left:50%; top:50%; margin-top:-80px; margin-left:-160px;}