Search code examples
javascriptjquerytoastr

calling jquery function for toastr notification


I want notifications from toastr to pop up when these links are clicked but nothing happens

EDIT: here is the jsfiddle of the full code http://jsfiddle.net/XaVcR/ I'm not sure if I included toastr properly though Success .js

toastr.options.closeButton = true;
toastr.options.positionClass = "toast-bottom-left";

$(document).ready(function() {
    $('#success').click(notification('success', 'this was a success!'));
});

function notification( type, message ) {
if( type == 'success' ) {
    toastr.success(message,'<i>Success</i>');
} else if( type == 'error' ) {
    toastr.error(message,'Error');
} else if( type == 'warning' ) {
    toastr.warning(message,'Warning');
} else {
    toastr.info(message,'Information');
}   
}

Solution

  • From the question:

        $('#success').click(notification('success', 'this was a success!'));
    

    This should be:

    $('#success').click(function() {
        notification('success', 'this was a success!');
    });
    

    Your JSFiddle has:

    $('#success').click(function() {
        notification('success', 'this was a success!'));
    });
    

    which, with the )) at the end of the middle line, is a syntax error.