1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development JS and css

Discussion in 'Software' started by linger, 5 Mar 2005.

  1. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    i'm writting a script and i want to know how to get the height of a div layer through javascript.
    I know i can get the height if the layer is using the style property like so
    html
    Code:
    <div id='blah' style='height:10px;'>...
    
    js
    Code:
    obj.style.height
    
    But i want to use classes, and i have not been able to figure it out.
    Html
    Code:
    <div id='blah' class='poo'>...
    
    I would really appreciate some help, i havent been able to find it on google.
    thx
    Jimmy
     
  2. A3M0N

    A3M0N What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    23
    Likes Received:
    0
    ok, to get the height, you want somthing like this:
    Code:
    height = document.getElementById('blah').style.height;
    
    i hope that javascript is right, if not, i'm sure someone will correct me :)

    and to use a class, you do this in your style sheet:
    Code:
    <style type="text/css">
    .poo {attributes: here; }
    </style>
    
    remeber, classes use a period(.) in the style sheet, and ids use a pound sign(#).

    good luck!

    later
     
  3. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    thanks for the reply, but everytime i've tried to get the height of the object when its using a class it returns undefined. When i dont use a class, and just do <div id='fsdf' style='height:blah;'>... it works fine. This is where i have the problem.
     
  4. alcedes

    alcedes What's a Dremel?

    Joined:
    1 Jan 2005
    Posts:
    121
    Likes Received:
    0
    Properties of interest

    offsetHeight offsetWidth
    offsetTop offsetLeft
    clientWidth clientHeight
    scrollTop scrollLeft
     
  5. A3M0N

    A3M0N What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    23
    Likes Received:
    0
    i think you actually have to set the height like that (per tag basis) to get the height and width from js. not 100% sure on that.

    good luck on your stuff though man. maybe someone with more experience in what you are trying to do will have a solution for ya.

    sorry man.

    later
     
  6. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    i figured out when setting it i can just use obj.style.height, and when getting it i can just use obj.offsetHeight
     
  7. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    i've got one more problem, i tried to implement this script into my xhtml page and it doesnt let me set the obj.style.left property anymore. But if i make the page regular html it works, but my page looks f* up. Any suggestions?
     
  8. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    no one can help?
     
  9. linger

    linger What's a Dremel?

    Joined:
    10 Feb 2005
    Posts:
    31
    Likes Received:
    0
    For anyone who wants to know i figured out how to fix the problem when using xhtml
    i had to do
    NodeElementChild.style.left = Location[0]+"px";
    instead of doing
    NodeElementChild.style.left = Location[0];

    i was just sitting there switching things around and this worked.
     
  10. A3M0N

    A3M0N What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    23
    Likes Received:
    0
    sweet, good job.

    later
     

Share This Page