Why the result is undefined?



Why when I run my code like this the result of the input will be undefined but if I replaced the

var toAdd = input;

with :

var toAdd = $('input[name=checkListItem]').val();

it will work correctly !

var input =  $('input[name=checkListItem]').val();
$(document).ready(function() {    
  $("#button").click(function() {
     var toAdd =  input;
     $(".list").append('<div class="item">' + toAdd + '</div>');
     $(document).on('click', '.item', function() {


Maybe you should read why the otherway is correct

or read
== the Book ==


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.