I want to know exact length in pixels of String i.e. "Hello World".
It should not be length of my container.
Any Help???
I want to know exact length in pixels of String i.e. "Hello World".
It should not be length of my container.
Any Help???
Put your text in a <span> and use JavaScript to measure the width of your <span>.
HTML:
<span id="text">Dummy text</span>
JavaScript:
var textWidth = document.getElementById("text").clientWidth;
jQuery:
$('#text').width();
span has a CSS style which sets its width to 100% for example!span is per definition an inline element. This means that you cannot define its width without changing its display to e.g. block or inline-block.