0
<script type="text/javascript">
    $(document).ready( function () { 
        $('#cell').css('height',$(window).height()+'px');
    });
</script>

as you see I have this script that defind the #cell's height to be as the page's height. but outside of this div i got another div that put it top=50% and margin-top=-218px to be in the middle of the screen. because of that, the height of the height of the page is bigger then is should be.

I tried to do something like this but i cant find the right syntax-

<script type="text/javascript">
    $(document).ready( function () { 
        var p = $("mainWrap");
        var position = p.position();
        heightPage = $(window).height()
        heightTop = position.top;
        heightFixed = heightPage - heightTop + "px";
        $('#cell').css('height', heightFixed);
    });
</script>

EDIT: i was able to do this like so

<script type="text/javascript">
 $(document).ready( function () { 
  var s = document.getElementById('cell');
  var fixedHeight = $(window).height() - s.offsetTop;
  fixedHeight = fixedHeight + "px";
  $('#cell').css('height',fixedHeight);
});

thanks for your comments.

for the guy that commented that ask for what i was trying to do: i centered my content by wrapping it with a DIV that pushing it to the middle by 'top:50%' and margin it back to the top so it will be in the middle by 'margin-top:208px' (its the height of the content). besides that, i got a footer that hides under the screen scrolled (no matter what is the resolution of the screen) and because of the centering thing, the footer was too much scrolled.. the top:50% pushed the footer deep down and i had to find a way to push it back up.. that is where the jquery part came in. i know there is a alot of ways to keep the footer down or under the screen but im working with a cms patform and there is alot of bugs and inherited css so it was too complicated.

anyhow everthing is ok now and its working, hope it will be usefull for someone someday.

thanks for the help.

4
  • On which line do you get the error? Commented May 24, 2012 at 8:44
  • missing a semi-colon on 5th line, for a start. Plus you should wrap the subtraction on line 7 (heightPage - heightTop) + "px"; Commented May 24, 2012 at 8:44
  • @musefan, semi-colons are automatically adding by the js engine, that is not the issue. Commented May 24, 2012 at 8:45
  • 1
    Can you explain exactly what you want? It seems to me that you're trying to center an object on the page. For that you normally wouldn't need javascript at all; just CSS. Commented May 24, 2012 at 8:46

1 Answer 1

3
var p = $("mainWrap");

needs some indicator if it is an ID (#) or a class(.). For an ID it should look like

var p = $("#mainWrap");

EDIT: As Ash pointed out, p will most probably be undefined and hence the next line will throw an error, because undefined has no property position.

Sign up to request clarification or add additional context in comments.

2 Comments

Good spot. You could explain therefore that p is likely to be null. +1 anyway.
@AshBurlaczenko p wouldn't be null, it would be an empty jquery object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.