dimanche 28 février 2016

Removal confirm with a pop-up message (jQuery)

I have a button with class .delete When I click it I want to run a jQuery code.
First of all I want to do this:
$('.pop-up-alert').addClass('clicked');

Then I need to run a function with if/else if/else statments.

  1. If .no-btn is clicked, I want to do this:
    $('.pop-up-alert').removeClass('clicked');

  2. Else if .yes-btn clicked, I want to do this:
    $(.delete).parent().remove(); // actually I need to delete only parent with .delete class child that was clicked (I need to use this somehow, but I don't know how)

  3. Else, I'm apllying this code again:
    $('.pop-up-alert').removeClass('clicked');

The point is, if user clicks the delete button, he gets a pop-up with the ability to confirm deleting. If he clicks YES, jQuery will delete the .delete parent. If NO, pop-up will be hidden (with .clicked class in CSS). But if he clicks anywhere else, pop-up will be hidden anyway.

If I understand it right, the code should be something like that:

$('.delete').click(function() {
    $('.pop-up-alert').addClass('clicked');
    function() {
        if ($('.no-btn').click()) {
            $('.pop-up-alert').removeClass('clicked');
        } else if ($('.yes-btn').click()) {
            $(.delete).parent().remove();
        } else {
            $('.pop-up-alert').removeClass('clicked');          
        };
    };
});

But it doesn't work. Please, help

Aucun commentaire:

Enregistrer un commentaire