/ LJCJSCodeDoc / LJCCommonLib / LJC / TextWidth


Parameters
font - A Font object.
text - A string value.

Returns

The text width in pixels.

Syntax

JavaScript
static TextWidth(font, text)

Gets the text width.

Example

JavaScript
// Gets the text width.
TextWidth()
{
  const element = document.body;
  const propertyName = "font";
  const font = LJC.ElementStyle(element, propertyName);
  const text = "This is sample text.";
  const value = LJC.TextWidth(font, text);
  const result = LJC.Round(value);

  // With font = "16px "Times New Roman"
  // result:
  // 124
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.