Detecting Where Text Wraps

Discussion in 'Javascript' started by Jeff Bigham, Aug 23, 2008.

  1. Jeff Bigham

    Jeff Bigham Guest

    Hi,

    If I have a DIV containing a single text node, is there a way to
    detect where (or if) the text in that node wraps?

    <div>
    Some text that possibly wraps to a second line.
    </div>

    I'd very much appreciate if someone could point me in the right
    direction, or even tell me that it's not likely to be easily
    accomplished.

    Thanks,
    Jeff
     
    Jeff Bigham, Aug 23, 2008
    #1
    1. Advertising

  2. Jeff Bigham wrote:

    > If I have a DIV containing a single text node, is there a way to
    > detect where (or if) the text in that node wraps?
    >
    > <div>
    > Some text that possibly wraps to a second line.
    > </div>


    IE exposes a method getClientRects which you could call on the div
    element object and check the length property of the collection returned.
    If it is greater than one then there are at least two lines of text in
    the div. Each item in the collection is a TextRectangle object with
    properties that should allow you to find where the text wraps
    See
    http://msdn.microsoft.com/en-us/library/ms536435(VS.85).aspx
    An example is here:
    http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/rectdemo.htm



    I think Firefox 3.0 implements that method too but I have so far not
    used it with Firefox so I don't know how compatible the implementations are.
    http://developer.mozilla.org/en/DOM/element.getClientRects


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thor W Hammer

    asp.net 2.0 wraps elements inside divs

    Thor W Hammer, Nov 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    317
    Erik Funkenbusch
    Nov 9, 2005
  2. RiGGa
    Replies:
    7
    Views:
    9,130
    Peter Otten
    Jun 19, 2004
  3. Lukas Kurka

    Get rid of div which wraps GridView

    Lukas Kurka, Aug 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,746
    =?Utf-8?B?Q1NoYXJwZ3V5?=
    Aug 22, 2006
  4. bpd

    Labels - text wraps at runtime

    bpd, Mar 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    327
  5. Mike
    Replies:
    0
    Views:
    86
Loading...

Share This Page