user1915190
user1915190

Reputation: 307

jQuery function when screen resizing

I want to add a class to an element when the screen width is smaller than 979px. Also when the screen is adjusting and wider than 979px, above added class should be removed.

This is the code I've tried, but its not working.

$(document).ready(function(){
   if(screen.width < 979) {
       $('.social').addClass('hide');
   }
});

Please help me fix this.

Thanks and Regards.

Upvotes: 0

Views: 81

Answers (2)

Sang Suantak
Sang Suantak

Reputation: 5265

Try this:

$(document).ready(function () {
  $(window).resize(function () {
    if ($(window).width() < 979) {
      $('.social').addClass('hide');
    } else {
      $('.social').removeClass('hide');
    }
  });
});

Upvotes: 2

Rutwick Gangurde
Rutwick Gangurde

Reputation: 4912

I guess this is what you need: resize.

Upvotes: 1

Related Questions