Results 1 to 4 of 4

Thread: How do I know the width of an element through javascript?

  1. #1
    Join Date
    Jan 2009
    Posts
    52

    How do I know the width of an element through javascript?

    There is a div defined field sizes. It is a text (in each case is different). A maximum size (size) of the text.
    Question: how to define the width of the text to dynamically reduce the size if it got the edges? If the current tag div invest another, but does not assign importance to the method

    Code:
    var q = document.getElementById ( 'qwerty');
    alert (q.currentStyle.width);

  2. #2
    Join Date
    Dec 2008
    Posts
    322

    Re: How do I know the width of an element through javascript?

    you can try with q.clientWidth

  3. #3
    Join Date
    Jan 2009
    Posts
    52

    Re: How do I know the width of an element through javascript?

    in IE returns the width of the previous element, if it is determined, or the width of the screen if the width of the previous element is not defined ... when viewing the properties of such a code

    Code:
    function ShowProperties () (
    var result;
    var objName = "qwerty";
    var q = document.getElementById ( "qwerty")
    for (var i in q) result + = objName + "." + I + "=" + q [i] + "<br /> \ n";

    document.all.item ( "result"). innerHTML = result;
    )
    I have not noticed any contains that the current width and can be any circuit to know the width of the text

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How do I know the width of an element through javascript?

    and you do so - and will become evident why

    Code:
    <div id='test' style='border: 1px solid black'> Some text here </ div>
    then both

    Code:
    <span id='test' style='border: 1px solid black'> Some text here </ span>
    <script>
    alert (document.getElementById ( 'test'). offsetWidth)
    </ script>

Similar Threads

  1. Replies: 5
    Last Post: 18-06-2011, 07:39 AM
  2. javascript get element by class
    By GlassFish in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 09:05 PM
  3. How to set the value of a form element using Javascript?
    By shivendra in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 05:04 AM
  4. Code to scroll to javascript element.
    By sizzla in forum Software Development
    Replies: 2
    Last Post: 04-07-2009, 10:13 PM
  5. JavaScript - How to create Element
    By Xylina in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 05:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,551,354.13233 seconds with 17 queries