I have some checkboxes which are used to show/hide columns and automatically resize them to fit the screen. I've linked the checkboxes to their relevent columns using a data attribute and try to read this value using jQuery.data(). This gives an error of "undefined is not a function" even though a breakpoint seems to show I have set my variables up properly up to this point.
HTML
<div class="col-xs-12">
<span>Show or hide columns:</span>
<input type="checkbox" checked="checked" id="column-selector" data-column="selectioncolumn" />Selection via dropdowns
<input type="checkbox" checked="checked" id="column-selector" data-column="listcolumn" />Selected items
<input type="checkbox" checked="checked" id="column-selector" data-column="mapcolumn" />Map
</div>
<div id="selectioncolumn" class="col-xs-4">
Div 1
</div>
<div id="listcolumn" class="col-xs-4">
Div 2
</div>
<div id="mapcolumn" class="col-xs-4">
Div 3
</div>
jQuery
$(document).ready(function () {
$('#column-selector').on('change', function () {
var numberOfColumns = $('#column-selector:checked').length;
var sizeOfVisibleColumn = numberOfColumns === 0 ? 4 : 12 / numberOfColumns;
var columnClass = 'col-xs-' + sizeOfVisibleColumn;
$.each($('#column-selector'), function (i, checkbox) {
var columnId = checkbox.data('column'); //Error occurs here
//More stuff
});
});
});
by setting a breakpoint I can see that the attribute has been set and the dataset populated.
However, the line var columnId = checkbox.data('column');
leads to the error "Uncaught TypeError: undefined is not a function". What have I done wrong?
JQuery version is 2.1.1 browser is Chrome 40.0.2214.111 m