Reputation: 13
I used this jQuery script to center my div based on browsers window resolution. However I can't get it working. What am I missing here?
I posted it in jsFiddle for better understanding here http://jsfiddle.net/9wvt3/
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
$(#main).center();
Upvotes: 0
Views: 247
Reputation: 49188
This:
$(#main).center();
Should probably be:
$('#main').center();
Note the '
in the $()
function argument.
Upvotes: 5
Reputation: 98718
You are simply missing the quotes on #main
within $('#main').center();
Upvotes: 3