Html – How to make a jQuery alert confirm box with “yes” and “no”

htmljquery

How can I make jQuery work with my HTML and CSS? I need when I click on the button and open an alert box in the centre with some text and options "yes" , "no" and when click yes to delete the text.

My code is here:

<div class="text">Some text here
    <a href="#" class="deleteMe">
        <span class="delete-icon"> x Delete </span>
    </a>
</div>

Demo


Best Answer

See the following snippet:

$(document).on("click", "a.deleteText", function() {
    if (confirm('Are you sure ?')) {
        $(this).prev('span.text').remove();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
    <span class="text">some text</span>
    <a href="#" class="deleteText"><span class="delete-icon"> x Delete </span></a>
</div>

Related Question