I am new to jQuery and especially to arrays and am trying to create an unordered list from an array. The array contains all unique values from certain parts of a table and creating this works as intended (tested via alert) but when I try to create a list with these values nothing (visible) happens.
Can someone tell me what I am doing wrong here ? Also, is there a way I can cover the case that the array does not contain any values and then just show a dummy or default item in the list ?
Note: '#test' is a test div where I was playing with this.
My jQuery:
$('#tblLegend td.col1').on('click', function(){
var tblValues = new Array();
$('#tblCalendar').find('tbody > div.editable').each(function(){
if(tblValues.indexOf($(this).text()) == -1){
tblValues.push($.trim($(this).text()));
}
});
var ul = '<ul>';
$.each(tblValues, function(i){
ul+= '<li>' + tblValues[i] + '</li>';
});
ul+= '</ul>';
$('#test').html(ul);
});
Many thanks in advance, Mike