469,612 Members | 1,523 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

JS (or JQuery): Find the point where a line wraps

FLEB
30
Is there a built-in function or a simplified method to tell where a given line of text wraps/will wrap in a given container (the container is fixed-width)? I want to chop off and add an ellipsis to some text at the point where it exceeds one line.

My best idea so far is to just create a dummy container with the same specs, off-screen or invisible, and feed words into it one-by-one, then return where the container changes height. This just seems like the "brute force" long way around the problem, but I don't know if there's a better way.
Oct 2 '08 #1
2 1593
rnd me
427 Expert 256MB
that's the trick i use, and it works.

there really is no other good way since firefox 3 zooms everything, making
calculations next to impossible.

i would write it into a reusable function that you can pass text and a style attrib to, and get back the width.

makes a nice addition to your script library.
Oct 2 '08 #2
FLEB
30
Excellent. Thanks.

________________________________
Oct 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by RiGGa | last post: by
1 post views Thread by joe shaboo | last post: by
1 post views Thread by chris | last post: by
2 posts views Thread by youpak2000 | last post: by
8 posts views Thread by Harris Kosmidis | last post: by
1 post views Thread by renu | last post: by
53 posts views Thread by Gianni Mariani | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.