使用jQuery基于屏幕大小添加div类

时间:2022-07-04 20:28:36

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:

我有一个div class =“容器,如果屏幕尺寸小于959px,我想添加到

:

Below is the code i am trying to use:

以下是我尝试使用的代码:

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


})

1 个解决方案

#1


1  

You forgot the } after the addClass

你在addClass之后忘记了}

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

#1


1  

You forgot the } after the addClass

你在addClass之后忘记了}

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