kelvinc
kelvinc

Reputation: 1

jQuery/Javascript if width issue

I can't seem to get my if statement working. I know that everything inside the if statement works, so would appreciate some help.

$(document).ready(function () {
    if(screen.width > 350) {
        $('#search').hide();
        $('.trigger').click(function () {
            $('#search').slideToggle("500");
        });
    }
});

Upvotes: 0

Views: 1009

Answers (2)

Mojtaba Pourmirzaei
Mojtaba Pourmirzaei

Reputation: 308

This returns width of browser viewport:

$(window).width();

This returns width of HTML document:

$(document).width();

Upvotes: 1

Robert Van Sant
Robert Van Sant

Reputation: 1507

try using:

if ($(window).width() > 350) {

or

 if ($(document).width() > 350) {

i hope it helps.

Upvotes: 1

Related Questions