-2

assume you have

<span class='class'>gfdsdfgfdsg</span>

How can i calculate how match size in pixel, i need for it, before it is rendered. (I don't search for auto adjust, only calculation.)

yantrab
  • 2,482
  • 4
  • 31
  • 52

1 Answers1

1

you can use use jquery.width() for this.

$('.class').width();
Andrew Daly
  • 537
  • 3
  • 12
  • $('gfdsdfgfdsg').width() return 0, and i not using jquery. – yantrab May 02 '19 at 10:54
  • @yantrab. Your entity must exist in the DOM: `$('
    ', { text: 'apples' }).appendTo('body').width()` == 1371, `$('
    ', { text: 'apples' }).width()` == 0
    – Glycerine May 02 '19 at 11:03