Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append() is not a function jQuery [closed]

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

like image 282
Laurent Meyer Avatar asked May 23 '15 16:05

Laurent Meyer


1 Answers

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>');
like image 118
Denys Séguret Avatar answered Sep 28 '22 03:09

Denys Séguret