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

how can i don't scroll long string by java script?

P: 3
For example I have a div tag with long sting that string length is greater than one line:
qwekmlkmckskmkmlkmlcmdhuhjefuybcvgdwelfjnfjevljhjn fukfmkdfolffneuwghqnnmldelmkeienfbuyheuytgpkrnbxhb ybwijemncksmczmcigvkfmmfrkmfkcmsewlkfklcwehrunrjng t

browsers show it in one line with scroll,but I want to go to the next line when the sting arrive to the end of line.
how can i do it with java script?
Oct 22 '13 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 8,639
you can use CSS3ís word-break property.
Oct 22 '13 #2

P: 3
Thanks,but I know it,
I want to do it by java script,because I want to continue the string in two lines later.
Do you know that how can I do this?
Oct 22 '13 #3

Expert Mod 5K+
P: 8,639
do you use a monospaced font?
Oct 22 '13 #4

P: 3
No,i don't use monospaced font.
Oct 22 '13 #5

Expert Mod 5K+
P: 8,639
then you can’t AFAIK cut the string on the border of the element, as I do not know that it is possible to determine the width of a part (after a certain count of characters) of a string.

the best bet would be a lucky guess based on the average length per character.

though if you have lots of time, you could create an inline element, fill it with a character, check its length, fill it with the next character, check length again and repeat until you reach the element border.

this is usually the job of the browser’s (HTML) rendering engine, which does not hook into the JS engine.
Oct 22 '13 #6

Post your reply

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