Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

word count alpine js

<div x-data="{ wordCount: 0 }" x-init="wordCount = $el.querySelector('textarea').value.trim().split(' ').length;">
  
  <textarea class="form-input border" rows=5 @keyup="wordCount = $event.target.value.trim().split(' ').length;"></textarea>
       
  <p class="text-xs" :class="wordCount < 20 ? 'text-red-700' : 'text-green-700'">Word counts: <span x-html="wordCount"></span> min: 20</p>
</div>
Source by codepen.io #
 
PREVIOUS NEXT
Tagged: #word #count #alpine #js
ADD COMMENT
Topic
Name
5+2 =