By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

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

FLEB
P: 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
Share this Question
Share on Google+
2 Replies


rnd me
Expert 100+
P: 427
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
P: 30
Excellent. Thanks.

________________________________
Oct 7 '08 #3

Post your reply

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