javascript - Use Jquery text().length inside of a textarea -
i found usefull text counter css class.
$(".quotecontent").filter(function() { return $(this).text().length < 40; }).parent().css('background', 'red');
http://jsfiddle.net/adeneo/kh8hh/
when arround container textarea, jquery code not working anymore. ideas?
see:
thank you
if examine content of textarea, you'll see there no dom elements there:
<textarea> <div class="quote"> <div class="quotestart"></div> <div class="quotecontent"><p>we have new toy!</p> <div class="author">- fernando alonso</div></div> <div class="quoteend"></div> </div> <div class="quote"> <div class="quotestart"></div> <div class="quotecontent"><p>fight fly, fly fight, fight win.</p> <div class="author">- motto of u.s. navy fighter weapons school, topgun</div></div> <div class="quoteend"></div> </div> </textarea>
all content inside textarea text. $(".quotecontent").length
0
.
one solution have separate dom element acting error containers, , can show div's errors there:
var errorwrapper = $('.error-wrapper'); errorwrapper.html($('textarea').text()); $(".quotecontent").filter(function() { return $(this).text().length < 40; }).parent().css('background', 'red'); $(".quotecontent").filter(function() { return $(this).text().length > 40; }).parent().remove();
Comments
Post a Comment