I'm quite new to JQuery (I come from Android World) and I do not understand why I'm stuck with Uncaught TypeError: $list.append is not a function
because I'm manipulating two jQuery Objects (as far as I know). So here is my code:
function transformInList(items, $list){
if ($.isArray(items)){
$.each(items, function(index, value){
var $li = $('<li />');
if (value.name && value.id){
$li.attr('id', value.id);
$li.text(value.name);
$li.attr('class', 'clickableJobs')
$list.append($li);
}
});
}
}
This code is called with this function:
$(document).ready(function(){
var $ul = ('<ul class="side-nav"></ul>');
var jobs = {"jobs":[{"name":"Kellner", "id":"j10"}, {"name":"Fahrer", "id":"j11"}, {"name":"Lehrer", "id":"j12"}]};
transformInList(jobs.jobs, $ul);
$('div#jobColumn').append($ul)
});
My error should be trivial (as is my code ) but I do not get it.
Thanks for help :D
Just a typo. You're passing a string, right now.
Change
var $ul = ('<ul class="side-nav"></ul>');
to
var $ul = $('<ul class="side-nav"></ul>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With