-2

I have the following jQuery to check how wide a should be if I want to fit my text (just for testing purposes), but it always gives me the same width back as my own width, what am I doing wrong?

var newWidth = $(this).clone().insertAfter($(this));
newWidth.width("");
console.log(newWidth.width() + ' ' + $(this).width());
newWidth.remove();

For example, in my HTML I have an tag that links to a German site, normally my is 100 px width. but now, the title of this German site is "Rechtsschutzversicherungsgesellschaften" which is way too long text to fit in 100px. I want to see how wide my should be, with my current font-size etc, in order to fit the whole text on one line.

Danny Hobo
  • 422
  • 5
  • 21

1 Answers1

0

You can use:

 newWidth.css('width', 'auto')

or

 newWidth.css('width', '');
Milind Anantwar
  • 79,642
  • 23
  • 92
  • 120