Link to home
Start Free TrialLog in
Avatar of atljarman
atljarman

asked on

Window Resize not firing Javascript/Jquery

Hi,

I have a jquery/javascript function that works great if you reload the page.  I would like to get this function in an OnReady function, but not sure if that is possible.  When reloading, after changing the screen dimension the function fires.  However, if you just do a resize of the window it does not.  I need it to fire everytime the window is resized.

    <script type="text/javascript">

        var eventFired = 0;
        if ($(window).width() < 960) {


            $(".topItems").hide();
            $(".siteBanner").hide();

        alert('Less than 960 - mobilized');

        } else {
            alert('More than 960 - demobilized');
            eventFired = 1;
        }

                    $(".topItems").hide();
                    $(".siteBanner").hide();

                    alert('Less than 960 resize - mobilized');
                } else {
                    alert('More than 960 resize');
                }
            }
        });

    </script>

Open in new window

SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atljarman
atljarman

ASKER

Thanks.  I can get this to work in the footer but not in the header of the document.  Any ideas?
? What do you mean it works in the footer but not the header - do you mean where you place the script?

Look where you include your JQuery library - it has to come after that.
Thank you guys.  I got it working.