Ex 8 Disable button 2


#1

Hi, I always get the same error message :

"Oups, merci de réessayer. Remember to disable the Post button after posting a new message."

My code :

var main = function() {
  $('.btn').click(function() {
    var post = $('.status-box').val();
    $('<li>').text(post).prependTo('.posts');
    $('.status-box').val('');
    $(".counter").text("140");
    $(".btn").addClass("disabled");
  });
  
$('.status-box').keyup(function() 
{
  var postLength = $(this).val().length;
  var charactersLeft = 140 - postLength;
  $('.counter').text(charactersLeft);
  
    if(charactersLeft < 0)
    {
        $('.btn').addClass('disabled');
    }
    else if (charactersLeft === 140)
    {
        $('.btn').addClass('disabled');
    }
    else 
    { 
        $('.btn').removeClass(); 
    }
});

    $('.btn').addClass('disabled');
        
};

$(document).ready(main);

I'm adding the 'disabled' attribute to the btn class, so what's happening?

Thanks for your help.


#2

Hey @digitalrockstar61628! Just one quick mistake. When you were removing the class you didnt specify your class here is the part you got wrong:

Just change that to:

 else 
    { 
        $('.btn').removeClass('disabled'); 
    }

Hope that helped! If it didnt please reply saying so!


#3

Thanks a lot amanuel2 !


#4

Thaknks, I was having the same problem. But not in French, obviously...