1 Replies - 8205 Views - Last Post: 26 August 2011 - 07:04 PM

#1 itdoell   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Getting height of div using .height and subtract in half?

Posted 26 August 2011 - 06:37 PM

I would like to get the values of the height of a div so I can use them, more specifically I would like to get half the height of a div... but I can't figure out how to do this.

<div id="mydiv"></div>

$('#mydiv').height();


that's about as far as I've managed to get... could someone please show me an example of how I would be able to get the height of a div and then subtract it in half and use that new value so that I could do something like...


$('#mydiv').css('margin-top', '--insert half of the height here--');


Any hel pis appreciated, thank you.

This post has been edited by itdoell: 26 August 2011 - 06:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting height of div using .height and subtract in half?

#2 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Getting height of div using .height and subtract in half?

Posted 26 August 2011 - 07:04 PM

Hi,

Why not just divide it by 2?
var half = parseInt($("#mydiv").height()) / 2;
$('#mydiv').css('margin-top',half);



Hope that helps :)
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1