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:

http://jsfiddle.net/e1j7xqsx/

thank you

if examine content of textarea, you'll see there no dom elements there:

    <textarea>     &lt;div class="quote"&gt;     &lt;div class="quotestart"&gt;&lt;/div&gt;     &lt;div class="quotecontent"&gt;&lt;p&gt;we have new toy!&lt;/p&gt;     &lt;div class="author"&gt;- fernando alonso&lt;/div&gt;&lt;/div&gt;     &lt;div class="quoteend"&gt;&lt;/div&gt;     &lt;/div&gt;      &lt;div class="quote"&gt;     &lt;div class="quotestart"&gt;&lt;/div&gt;     &lt;div class="quotecontent"&gt;&lt;p&gt;fight fly, fly fight, fight win.&lt;/p&gt;     &lt;div class="author"&gt;- motto of u.s. navy fighter weapons school, topgun&lt;/div&gt;&lt;/div&gt;     &lt;div class="quoteend"&gt;&lt;/div&gt;     &lt;/div&gt;     </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

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -