7.Disable the button 1


#1

I don't know what the problem is.Please check below
My code:
var main = function() {

$('.btn').click(function() {
var post = $('.status-box').val();
$('

  • ').text(post).prependTo('.posts');

    $('.status-box').val('');
    $('.counter').text(140);
    });

    $('.status-box').keyup(function() {
    var postLength = $(this).val().length;
    var charactersLeft = 140 - postLength;
    $('.counter').text(charactersLeft);

    if (charactersLeft < 0) {
    $('.btn').addClass('disabled');
    }

    else if (characterLeft == 140) {
    $('.btn').addClass('disabled');
    }

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

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


  • #2

    @etthegeek,
    You are not closing-of the =main= function with a closing-curly-bracket-}...
    and you are not executing the =main= function by using the jQuery ready() facility
    like

    $(document).ready(main);

    have a read
    http://www.codecademy.com/forum_questions/555071a551b8870e9a00056e

    and it would be nice to see the HTML-code you use within your jQuery-statement,

    re-edit your Post

    • leave one blank-line above of your code
    • select your code in the Post
    • then =click= on the </>-symbol-of-this-editor

    Your code will then be in a pre-code state
    and you will be able to make/present the proper indentations.

    or even better use
    = http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697
    [extra's]
    https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


    #3

    @etthegeek,

    # status update

    class-name disabled....

    Where is style for that class?
    Styling is an Attribute of an Element.
    In the style.css-file
    I was wondering where is disabled class.

    The "disabled" class-name is -set- by you via the Javascript app.js
    as an additional class Attribute of
    the a-Element, which you identify by the class-name "btn"

    The sole purpose of the "disabled" class-name
    is to have an indication, if the
    identified by the class-name "status-box"
    has 1 or more characters -set-

    If the a-Element has the _"disabled" class-name as a class Attribute set,
    the Button-Functionality is Blocked.
    ( you use the Bootstrap-functionality )

    Reference::

    http://getbootstrap.com/javascript/