0

I would like to add 'span' tag on the beginning and '/span' on the end of each line of text as it is presented in the website and change it dynamically when a div containing such text is resized. The problem is that I don't know how to detect where the text is being wrapped - if I had such information it would be easy. So my question is: is there a way to determine where the text is wrapped using javascript? I have found a javascript library which hyphenates the text in the site but I'm not sure how does it detect line wraps. The working example is here and it's source can be found here.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
kremuwa
  • 447
  • 2
  • 5
  • 20
  • 1
    There's no way to do this, AFAIK. What are you trying to achieve? Are you trying to alternate the line colours or something? – Tim Rogers May 13 '11 at 10:50
  • Ok, thanks, I think there is a way (calculating text width by adding the width of each letter) but it's really dirty. If you could write the same as an answer I would accept it. Thanks in advance. – kremuwa May 13 '11 at 21:08

1 Answers1

0

yes, this is like to Search For and Highlight Text.
using javascript you can learn it here:

Search For and Highlight Text

or here:

how-can-i-use-jquery-to-style-parts-of-all-instances-of-a-specific-word

just download/save the web page there and you can learn it.

Community
  • 1
  • 1
bungdito
  • 3,556
  • 4
  • 31
  • 38
  • I'm not sure if you got me well - yes, your example shows how to add tags at the beginning and the end of a word/phrase. But my problem is not the part of adding the tags but determining where to add them - I would like to put `` on the beginning of each line of the text and '' on the end of it. – kremuwa May 13 '11 at 09:02
  • But it's still an answer for another problem - I still don't know WHERE to add the tags in the text. I knew HOW to do it from the very beggining. I want to know where the text overflows the div in which it is put where is it wrapped, moved to a new line. – kremuwa May 13 '11 at 10:17