click function on Bottstrap toggle button

click function on Bottstrap toggle button

Hi,

I´m generating two toggle buttons in my site:

  1. function addDataLayerToggleItems( layerName, layer) {
    $( "#LayerControl-List-DataLayer-Items"). append(
    $( "<div>", { class: "checkbox" }). append(
    $( '<input>', {
    type: "checkbox",
    id: layerName,
    'data-toggle' : "toggle",
    'data-on' : "Ein",
    'data-off' : "Aus",
    'data-on' : "Ein",
    'data-off' : "Aus",
    'data-onstyle' : "success",
    'data-offstyle' : "danger",
    class: "toggle"
    })
    ). append(
    $( '<label>'). text( layerName)
    )
    )
    }
how do I generate a click event to do something when the toggle change?

  1. tried with: $('input:checkbox').change(function() {
    // $('#console-event').html('Toggle: ' + $(this).prop('checked'));
    console. log( "Change event: " + this. id);
    debugger;
    console. log( "aaaaaaahhhhhhhhhhhhhhhh");
    })