All articles, tagged with “jquery”

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;
    });
}

Turn table rows and buttons into clickable links with jQuery

This simple little script often comes in quite handy when I’m working on a web app. It allow you to add an href attribute to tr, td, or input[type=button] tags to make them clickable links

$(function() {
    $("input[type=button][href], tr[href], td[href]").click(function() {
        location.href = $(this).attr("href");
    });
});