13/14 jQuery Is this a bug or I'm overseeing a syntax error?


#1

Hello everyone,

Both codes that are exactly the same (except for the indentation), both will let me pass to the next lesson, but only one do what it supposes to do:

This one doesn't work but still it lets me go to the next lesson.

 $(document).ready(function(){

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

And this one with a different indentation but exactly with the same code will work:.

 $(document).ready(function(){

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

My question is, why? Does jQuery have a python-like behavior regarding indentation? Have I missed something? Is just a compiler bug?


#2

$(document)on('click','.item',function() {

here is a mistake.try to find it :slight_smile:


#3

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