scott_001
scott_001

Reputation: 1

JQuery - Window resize working on Chrome but not Firefox

I have the code below to show the Larger tracker on wider screens and the smaller tracker otherwise, but it is only working for me in Chrome and I can't get it to function in Firefox.

I'm not that familiar with JQuery, so I suspect it may just be a syntax error which Chrome is more forgiving of but I haven't been able to find the error when searching. Thanks for the help.

    $(window).resize(function() {
    var wi = $(window).width();

    if (wi <= 767){
        $('.LargerTracker').hide();
        $('.SmallerTracker').show();
        }
    else {
        $('.LargerTracker').show();
        $('.SmallerTracker').hide();
        }
    });

Upvotes: 0

Views: 935

Answers (1)

Brett
Brett

Reputation: 589

It looks like your logic is fine, you can see a working example here http://jsfiddle.net/ygxbtt6c/3/

Without seeing more code I can't tell for sure, but it's possible that you need to wait for the DOM ready event before binding your function to the window resize event.

$( document ).ready(function() {
  // DOM is ready to be manipulated, put your code here
});

You can learn more about the ready event in the jQuery documentation

Upvotes: 1

Related Questions