Add confirm dialog to a link with jQuery

Here’s another simple jQuery snippet I like to add to my projects. This will allow you to present a javascript confirm dialog when a user clicks on a link or a submit button with a confirm attribute it. The value of the confirm attribute will be the text displayed in the confirm dialog box. I often use this for delete button so the user has a chance to back out.

$(function() {
    $("a[confirm], input[type=submit][confirm]").click(function() {
        conf = confirm($(this).attr("confirm"));
        if(!conf)
            return false;
    });
}
Add post to:   Delicious Reddit Slashdot Digg Technorati Google
Make comment

Comments

No comments for this post

Required. 30 chars of fewer.

Required.

captcha image Please, enter symbols, which you see on the image