JSFiddle - React, Tailwind, and code Playground

HTML

<div>hello this is a test</div>

JavaScript

$.fn.textWidth = function()
{
    var old = $(this).html();
    $(this).html( $("<span>").html( $(this).html() ) );
    var width = $(this).find("span:first").width();
    $(this).html(old);
    return width;
};

alert("Width of the text in the div = " + $("div").textWidth());