$ (window) .height () returns wrong value

I cannot get the correct value when running $(window).height()

at www.presenskonferens.se . This is the same in all browsers.

Here is the code I'm using:

// Screen height sections
$(function() {

    function screen_height() {
        $('.screen-height').css({'height': $(window).height() });
    }

    screen_height();
    window.addEventListener("orientationchange", screen_height );
    $(window).resize( screen_height );

});

      

Here's what I've tried:

  • Using the correct doctype ( <!DOCTYPE html>

    )
  • Removing all content in the div of interest
  • Removing all content in js file except for screen_height function
  • Removing everything in the screen_height function except $('.screen-height').css({'height': $(window).height() });

  • Executing console.log for $(window).height()

    and getting 12191 in response

I'm stumped. As far as I can tell, the error happened when the site was upgraded to WordPress 4.0, but it doesn't use the jQuery version that comes with WordPress. Any help is appreciated.

+3


source to share


1 answer


When the doctype is not set correctly, jQuery treats $(window).height()

the same as $(document).height()

.

You used the correct doctype ( <!DOCTYPE html>

), but by adding your analytic code to it, you made it invalid.



Move your analytic code to the head, before the closing tag </head>

, and everything should work fine.

Edit: I just noticed that you have two different analytics code blocks. Get rid of the highest (on line 1).

+1


source







All Articles