JSFiddle - React, Tailwind, and code Playground

HTML

<p>try counting while putting some white spaces on span then press run above.</p>
<span>             </span>

JavaScript

alert('number of spaces: ' + $('span').contents()[0].nodeValue.length)