JSFiddle - React, Tailwind, and code Playground

HTML

<div class="cell" id="test">122</div>

CSS

.cell {
   width: 30px;display:inline-block;
}

JavaScript

$.fn.textWidth = function(){
  var html_org = $(this).html();
  var html_calc = '<span>' + html_org + '</span>';
  $(this).html(html_calc);
  var width = $(this).find('span:first').width();
  $(this).html(html_org);
  return width;
};

$(function(){
alert($('.cell').textWidth());

})