http://jsfiddle.net/e1j7xqsx/
ありがとう:
<textarea>
<div class="quote">
<div class="quotestart"></div>
<div class="quotecontent"><p>We have a 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 to fly, fly to fight, fight to win.</p>
<div class="author">- Motto of the U.S. Navy Fighter Weapons School, TOPGUN</div></div>
<div class="quoteend"></div>
</div>
</textarea>
すべてテキストエリア内のコンテンツはテキストです。したがって、$(".quotecontent").length
は0
です。
一つの解決策は、エラーのコンテナとして動作する別のDOM要素を持っている、とあなたはそこにエラーが発生したのdivのを示すことができる可能性があり
: ``それが価値だとして扱うので、私の間の任意のコンテンツを
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();
2番目の例で何が起きるかわからない –
textareaと同じ動作です。私のクラスはテキストエリアの中にあり、ユーザーがフルクオート(x単語以上)をすると、エラーメッセージを表示する必要があります。 – labu77