append() is not a function jQuery
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>');
Laurent Meyer
BY DAY: Crazy quick and dirty coder writing tests only if mentioned in the ticket. BY NIGHT: Crazy quick and dirty coder writing tests only if mentioned in the ticket (and sometimes sleeping :D) Specificities: Writes code with two fingers because is suffering of a very big lack of coordination Finds that reverse engineering your app is a cool hobby. Looks for security breaches in apps, because cannot remember his own passwords... Don't like bullshit and just get it done. Languages mastered: Java, Python, Javascript, React Native Fair level: Typescript, AngularJS, Postgres, React/Redux API Mastered: Android, Parse, Scrapy, Flask Favourite Stack: Postgres, Flask, Plain HTML or React, React Native
Updated on June 14, 2022Comments
-
Laurent Meyer over 1 year
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