"Count Characters Left", Why Doesn't this Work?



Why this doesn't work ?

var main = function() {
  $('.btn').click(function() {
    var post = $('.status-box').val();
    $('.status-box').val() = $('.status-box').val('');
    var postLenght = $(this).val().lenght;
    var charactersLeft = 140 - postLenght;


What exactly you are trying to accomplish with this code?


$('.status-box').val() = $('.status-box').val('');

It doesn't make any sense.what does it mean?what do you want?

and here

var postLenght = $(this).val().lenght;

check the spelling of length


Hi @arrayninja33611,

$('.status-box').val() = $('.status-box').val('');

The first half of that line (equal sign and before) is unnecessary. Calling .val(""); on a text input element will clear the element without you setting anything equal to the result of that operation.

You've also misspelled length several times :slight_smile:


I want to count the characters left


Now it works .
Thank you :slight_smile:


This topic is solved.