jQuery position div in middle of page

html, jquery

Solution

**It shouldn't be in quotes. Also, you need to use the `$()` terminology. Try this:

$("#a").css('margin-top', $(document).height()/2 - $("#a").height()/2);

Or even better:

var $a = $("#a");
$a.css('margin-top', $(document).height()/2 - $a.height()/2);

Edit: Just to be clear, you can't put it in quotes because it will try to set the margin-top property literally to that string. Which is incorrect.

Problem

Okay, so I have a div and I want to position it in the middle of a page. I've gotten so far ``` $("#a").css('margin-top', '(document).height()/2 - ("#a").height()/2'); ``` Is this correct?

Original source