user38208
user38208

Reputation: 1094

Adding a div class based on screen size using jQuery

I have a div class="container that I would like to add to <div class="second-menu-it"> if the screen size is less than 959px:

Below is the code i am trying to use:

$(window).on('resize', function() {
if($(window).width() < 959) {
    $('.second-menu-it').addClass('container');


})

Upvotes: 3

Views: 5725

Answers (1)

pedrodj46
pedrodj46

Reputation: 161

You forgot the } after the addClass

$(window).on('resize', function() {
    if($(window).width() < 959) {
        $('.second-menu-it').addClass('container');
    }
});

Upvotes: 3

Related Questions