JSFiddle - React, Tailwind, and code Playground

HTML

<div id="foo">&darr;</div>
<div id="bar">&nbsp;</div>
<input type="button" id="darrButton" value="Show darr length">
<input type="button" id="nbspButton" value="Show nbsp length">

JavaScript

function alertLength(element) { 
    
    alert("" + element.innerHTML.length);
    
}

function showNbspLength() {
    
    alertLength(document.getElementById("bar"));
                
}

function showDarrLength() {
    
    alertLength(document.getElementById("foo"));
    
}

document.getElementById("nbspButton").onclick = showNbspLength;

document.getElementById("darrButton").onclick = showDarrLength;