3

I'm trying to figure out with this isn't working. It used to take care of height instead of width, but i simply can't get it it work. Anyone could point me in the right direction of the problem perhaps?

            function getWindowWidth() {
        var windowWidth = 0;
        if (typeof(window.innerWidth) == 'number') {
            innerWidth = window.innerWidth;
        }
        else {
            if (document.documentElement && document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            }
            else {
                if (document.body && document.body.clientWidth) {
                    windowWidth = document.body.clientWidth;
                }
            }
        }
        return windowWidth;
    }
    function Removewhensmall(id) {
        if (document.getElementById) {
            var windowWidth = getWindowWidth();
            if (windowWidth > 0) {


              var contentElement = document.getElementById(id);
                var contentWidth = contentElement.offsetWidth;

                if (windowWidth < 600) {
                    contentElement.style.display = 'none';


                }


            }
        }
    }
    window.onload = function() {

Removewhensmall('rightwrap');
    Removewhensmall('leftwrap2');

    }
    window.onresize = function() {

            Removewhensmall('rightwrap');
    Removewhensmall('leftwrap2');

    } 

1 Answer 1

3
    if (typeof(window.innerWidth) == 'number') {
        innerWidth = window.innerWidth;
    }

shouldn't that be

    if (typeof(window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }

?

And further in the code

var contentWidth = contentElement.offsetWidth;

is defined, but contentWidth is never used again...

Also, you should make use of elseif() to prevent many nested if-clausules.

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

1 Comment

if (typeof(window.innerWidth) == 'number') { windowWidth = window.innerWidth; } was the main problem.

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.