Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1101627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:03:46+00:00 2026-05-17T01:03:46+00:00

I am trying to update my javascript to be jquery. Here is the javascript

  • 0

I am trying to update my javascript to be jquery.

Here is the javascript (this is working correctly)

<script type="text/javascript">

    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof (window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else {
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
            }
        }
        return windowHeight;
    }
    function setContent() {
        if (document.getElementById) {
            var windowHeight = getWindowHeight();
            if (windowHeight > 0) {
                var contentElement = document.getElementById('content')
                var contentHeight = contentElement.offsetHeight;

                if (windowHeight - contentHeight > 0) {
                    contentElement.style.position = 'relative';
                    contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
                    contentElement.style.visibility = 'visible';
                }
                else {
                    contentElement.style.position = 'static';

                    contentElement.style.visibility = 'visible';
                }
            }
        }
    }

    window.onload = function () {
        setContent();
    }
    window.onresize = function () {
        setContent();
    }

</script>

Here is the jquery (this just returns a blank screen without errors)

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">

    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof (window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if ($.documentElement && $.documentElement.clientHeight) {
                windowHeight = $.documentElement.clientHeight;
            }
            else {
                if ($.body && $.body.clientHeight) {
                    windowHeight = $.body.clientHeight;
                }
            }
        }
        return windowHeight;
    }
    function setContent() {
        if ($) {
            var windowHeight = getWindowHeight();
            if (windowHeight > 0) {
                var contentElement = $('content')
                var contentHeight = contentElement.offsetHeight;

                if (windowHeight - contentHeight > 0) {
                    contentElement.style.position = 'relative';
                    contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
                    contentElement.style.visibility = 'visible';
                }
                else {
                    contentElement.style.position = 'static';

                    contentElement.style.visibility = 'visible';
                }
            }
        }
    }

    $(document).ready= function () {
        setContent();
    }
    $(document).onresize = function () {
        setContent();
    }

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:03:46+00:00Added an answer on May 17, 2026 at 1:03 am

    Your function bindings at the end are a bit off, they should look like this:

    $(setContent);
    $(window).resize(setContent);
    

    This will lead to other errors though, $ isn’t a replacement for document, overall I think this is what you’re looking for:

    function setContent() {
      var windowHeight = $(window).height();
      if (windowHeight > 0) {
        var contentHeight = $('#content').height();
    
        if (windowHeight - contentHeight > 0) {
          $('#content').css({ position: 'relative', 
                              top: ((windowHeight / 2) - (contentHeight / 2)) + 'px',
                              visibility: 'visible' });
        }
        else {
          $('#content').css({ position: 'static',
                              visibility: 'visible' });
        }
      }
    }
    
    $(setContent);
    $(window).resize(setContent);​
    

    You can give it a try here, a few notes on this compared to the code in the question:

    • document.getElementById('content') is $('#content'), notice the # for an #ID selector.
    • $(window).height() uses .height() to take care of the cross browser/various case heights.
    • You can’t replace document with $, they’re very different things 🙂
    • .css() takes an object, so you can shorten you style setting above.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: I did get this working, here is the new javascript: $(document).ready(function() { $('a').click(
Update2: Here is jQuery included (along with current jQuery): <script type=text/javascript src=/honors/thesis_submission/js/jquery-ui.js></script> domain is
I am trying update text views while this loop is processing. Here is my
When trying to update a subversion working copy from Netbeans, I get the following
I'm trying to update some existing code that normally runs a Perl script which
Trying to send POST request on click event using jQuery with no luck. Here
Tools: Visual Studio 2010 I'm trying to learn jQuery, but I cant make this
I am trying to make a call with this script, but am getting a
Hi I am trying to make a jquery no conflict work as descriped here:
I am creating some thumbnails dynamically with JQuery, like this (in a loop): var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.