What about this example for your query on how to horizontally and vertically center that div in javascript
Please have a look
A method (JSFiddle example)
CSS:
html, body { margin: 0; padding: 0; width: 100%; height: 100%; display: table }
#content { display: table-cell; text-align: center; vertical-align: middle; }
HTML:
<div id="content"> Content goes here </div>