agurchand
agurchand

Reputation: 1665

How to find number of characters in a div line by line?

here is the image to explain it

div line

<div id="tshirt">
    <div id="text-wrapper">
        <p id="tshirtover">Nothing is impossible unless we try it</p>
    </div>
</div>

Is there any way to find the length of the first line?

I tried below jQuery function. It's giving the entire length of the string.

$("#tshirtover").text().length;

But i need to find only the first line. Is it possible to get it?

Upvotes: 2

Views: 1166

Answers (1)

Soheil Jadidian
Soheil Jadidian

Reputation: 888

the only way I can think of, is to create the empty div (with a fixed width), then start filling in the text character by character, use a counter to store how many characters have been put and also watch the height of the div, as soon as the height changes it means a new line has just started.

Upvotes: 2

Related Questions