Last active
August 1, 2016 07:13
-
-
Save Ahnita/a3fbb3836016b2ff85c215c11cc0a375 to your computer and use it in GitHub Desktop.
To create posts using JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var main =function() { | |
$('.btn').click(function() { | |
var post = $('status-box').val(); | |
$('<li>').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); | |
}); | |
} | |
$(document).ready(main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
$('.btn').removeClass('disabled'); | |
} | |
}); | |
$('.btn').addClass('disabled'); | |
} | |
$(document).ready(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the second version, the button is enabled only if the user types something in the post box. The post button is disabled when the characters is more than 140 characters.