[Solved] jQuery click event not firing on button element


You need to give the click handler the reference to your cookiesDismiss() function, not the result of the function.

Also note that you need to precede the document ready handler with a $, and checked is not a property of a jQuery object; you need to use prop('checked') to get the state of the checkbox.

$(function() {
    $('#cookiesbutton').click(cookiesDismiss); // note the removal of ()
});

function cookiesDismiss() {
    var cookieConsent = $('#cookie-checkbox');

    if (!cookieConsent.prop('checked')) {
        alert("Cookie removed");
    } else {
        alert("Modal hidden");
    }
}

Updated fiddle

2

solved jQuery click event not firing on button element