i am developing twitter like count characters and also limit its chacarter to only 160, when the text length is greater than 160 i want to addClass() to the 161st-last character so the 161st-last character have text-decoration as line-through. Basicly i can get out length text using substring(). But how to addClass to that substringed text here's my code:
$(document).ready(function(){
$("#tweet").attr("disabled","disabled");
$("#area").keyup(function(){
var chars=$(this).val().length;
$("#message").text(160-chars);
if(chars > 160 || chars <=0){
$("#tweet").attr("disabled","disabled");
$("#message").addClass("minus");
$(this).css("text-decoration","line-through"); //i want this in 161st-last character not on all text
}else{
$("#tweet").removeAttr("disabled");
$("#message").removeClass("minus");
$(this).css("text-decoration","");
}
});
});
html
<div id="box">
<p>(Maximum Allowed Characters : 160)</p>
<p><textarea id="area" rows="10" cols="40"></textarea></p>
<span id="message"> 160 </span> Characters Remaining
<input type="button" id="tweet" value="Tweet"/>
</div>
and here's my jsfiddle http://jsfiddle.net/ZM9WD/4/
ps:sorry for my english :-)