JSFiddle - React, Tailwind, and code Playground

by Nechifor Vasile

HTML

<div id="calculated"></div>
<div id="rendered"></div>
<br />
<span>Hello World</span>

CSS

span{
    font:30px Arial;
}

JavaScript

function get_tex_width(txt, font) {
    this.element = document.createElement('canvas');
    this.context = this.element.getContext("2d");
    this.context.font = font;
    return this.context.measureText(txt).width;
}
$("#calculated").html('Calculated width ' + get_tex_width("Hello World", "30px Arial"));

$("#rendered").html("Span text width "+$("span").width());