SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating height of box

    Lets say that you have the following code.

    Code:
    <div id="box">
    <p style="font: 1em Georgia">Lorem ipsum dolor sit amet, 
    consectetuer adipiscing elit. Sed mi pede, vehicula eget, 
    dapibus eu, tempus vitae, orci. Pellentesque habitant morbi 
    tristique senectus et netus et malesuada fames ac turpis 
    egestas. Quisque tincidunt luctus nisi. Aenean vitae sapien.
     Integertortor est, convallis eget, pretium eu, ornare in, 
    ligula. Cras nisl justo, aliquam et, laoreet venenatis, facilisis 
    vel, velit. Donec sed nulla et libero lacinia scelerisque. 
    Fusce lacinia. Vestibulum fermentum molestie purus. Morbi 
    rutrum congue tellus. Donec varius scelerisque nunc. 
    Nullam pellentesque turpis eu pede. Pellentesque dolor.
    Nulla cursus, tellus nec mollis interdum, mauris lorem
    consectetuer eros, ut malesuada pede eros dignissim ante.
    Phasellus a odio. Nullam massa. Etiam sit amet nisi sit 
    amet augue posuere rutrum. Donec tincidunt felis 
    dictum lorem. Sed tincidunt adipiscing lacus. Morbi eros.
    </p>
    </div>
    Is there any way you can, with use of a script calculate the generated height of #box?
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  2. #2
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.getElementById("box").clientHeight
    Cheers,
    D.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There's also getComputedStyle which is part of the standard, whereas clientHeight isn't. Internet Explorer doesn't support getComputedStyle, but Mozilla, Safari and Opera do.

  4. #4
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that isn't very helpful, given that IE has around an 80&#37; share of the browser market.

    Cheers,
    D.

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So? You can use both with object detection. Doing it the right way for the good browsers and the nasty way for the bad browser is better than doing it the nasty way for all the browsers.

    BTW, according to this, offsetHeight has slightly better browser support than clientHeight.

  6. #6
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use offsetHeight then. My point is that it's just obstinate to recommend a method that won't work on the world's most commonly used browser just because you don't happen to like it.

    Surely practicality trumps personal agendas?

    Cheers,
    D.

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's not because I like it, it's because it's based on a standard. However, realistically speaking you are right in that when it comes to creating a cross-browser application, obviously you have to use the most cross-browser methods.

  8. #8
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree that it's unfortunate, but IE's lack of standards is a de facto standard by virtue of its ubiquity and we just have to learn to live with it.

    Nothing some feature/browser sniffing can't fix anyway.

    Cheers,
    D.


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
  •