E
E
Extramezz2015-11-09 13:39:22
JavaScript
Extramezz, 2015-11-09 13:39:22

How to get the width of an element that is outside the DOM?

In general, I create an element elem = $("<div />");and add text to it elem.text("Блаблабла");.

And now, when there is text in it, its width is supposedly increased, but it elem.width()returns 0.

Ps: I need to fix the current width so that when the element is added to the DOM, the text inside this element changes, but the element itself does not become larger than was originally with the first text. How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2015-11-09
@Extramezz

You can fix the width at the CSS level, for example max-width. Or for example overflow: hidden; (overflow-x, overflow-y). The question is not entirely clear, therefore a vague answer.
And an element outside the DOM has no width, i.e. at all.

M
Mikhail, 2015-11-09
Chirskiy @chirskiy_mixail

Something like this?
jsfiddle.net/akc4nau3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question