arrow_back
Back

jQuery snippets: modals, forms, and common DOM patterns

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

How to send a form from a Bootstrap modal window:

$(function () {
    $(".submit-modal-form-button").on('click', function() {
        $(this).closest('.modal-content').find('.modal-body form').submit();
    });
});

We need to add a CSS class submit-modal-form-button.

Or without it:

$('.modal-footer button:last-child').click(function() {
    $(this).closest('.modal-content').find('.modal-body form').submit();
});

Check a checkbox

Use the :checked pseudo-selector:

$('#js-i-agree').on('change', function () {
    $(this).is(':checked');
});

Build a query string from an object

const params = {
    action: 'one',
    name: 'two',
    amount: 'three'
};

const uri = $.param(params);
// Result: "action=one&name=two&amount=three"

Libraries

Tooltips: open_in_new darktooltip .

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward