471,863 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

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 1638
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 YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.