title: Leaflet : Bootstrap Toggle input for on/off layer is does not work properly
body: <p>I made a button to turn the layer on and off using Bootstrap Toggle. When all buttons are tried to be turned on and off, the data that appears is the same data. Each data should have 1 button according to the ID <code>lyrMosaicSP</code> or <code>lyrMosaicLS</code> on the input. You can check it here <a href="http://jsfiddle.net/valensi/z0ugy5ar/22/" rel="nofollow noreferrer">http://jsfiddle.net/valensi/z0ugy5ar/22/</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
    osmAttrib = '&amp;copy; &lt;a href="http://openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors',
    osm = L.tileLayer(osmUrl, {
      maxZoom: 18,
      attribution: osmAttrib
    });
  
  var map = L.map('map').setView([0.4901708, 103.9593973], 9).addLayer(osm);
  
  var data = $.getJSON(jsondata,
    function(data) {
      for (var i = 0; i &lt; data.wiki_spbn.records.length; i++) {
        var layerVar = data.wiki_spbn.records[i][1];
        var layerUrl = data.wiki_spbn.records[i][3];
        var layerName = data.wiki_spbn.records[i][4];
        var layerFormat = data.wiki_spbn.records[i][5];
        var layerTransparent = data.wiki_spbn.records[i][6];
        var layerVersion = data.wiki_spbn.records[i][7];
        var layerAttribution = data.wiki_spbn.records[i][10];
  
        var layernya = L.tileLayer.wms('http://103.16.223.172:8080/geoserver/Prov_Kepri/wms', {
          layers: layerName,
          format: layerFormat,
          transparent: layerTransparent,
          version: layerVersion,
          attribution: layerVar
        });
  
        $('#' + layerVar).change(function() {
          if ($(this).prop('checked') == true)
            map.addLayer(layernya);
          else
            map.removeLayer(layernya);
        })
      }
    }
  );</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="checkbox" id="lyrMosaicSP" data-toggle="toggle" data-onstyle="success" data-size="small" /&gt;lyrMosaicSP&lt;br&gt;
  &lt;input type="checkbox" id="lyrMosaicLS" data-toggle="toggle" data-onstyle="success" data-size="small" /&gt;lyrMosaicLS
  &lt;div id="map"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>JSON:</p>
  
  <pre><code>{
    "wiki_spbn": {
      "columns": ["id", "var", "type", "url", "layers", "format", "transparent", "version", "minZoom", "maxZoom", "attribution"],
      "records": [
        [0, "lyrMosaicSP", "tile", "pustekdataUrl", "Mosaik SPOT 2014-2016 Prov Kepri", "image\/png", "true", "1.0.0", null, null, "Data Mosaik SPOT 2014-2016 Prov Kepri"],
        [1, "lyrMosaicLS", "wms", "pustekdataUrl", "Mosaik Landsat 2016-2017 Prov Kepri", "image\/png", "true", "1.0.0", null, null, "Data Mosaik Landsat 2016-2017 Prov Kepri"]
      ]
    }
  }
  </code></pre>