Unable to remove a class from a div on small screens using Jquery

1333 views javascript html jquery
6

I am trying to remove a class from a few divs on small screens but unfortunately no success. Is there anything wrong with the following code.

$(document).ready(function () {
    if ($(window).width() < 1025) {
        $('body').removeClass('heightFull');
        $('#v-pills-step8').hide();
    }
});

answered question

Wrong selector - you may mean $('div').removeClass('heightFull');. Also you want to check your doctype: <!doctype html>

There is nothing syntactically wrong with your code, but we don't know if it is correct for your page because you haven't shown us the HTML it applies to :) Are you sure it is the body tag you want?

@FluffyKitten remove a class from a few divs

@mplungjan Yes I was trying to prompt them into applying a bit of thought to it themselves :) (And pointing out there's a difference between syntactically wrong and logically wrong)

@Bloom a better solution might be to use css @media queries

1 Answer

4

You are selecting the body element. Try:

$(document).ready(function () {
    if ($(window).width() < 1025) {
        $('body div').removeClass('heightFull');
        $('#v-pills-step8').hide();
    }
});

posted this

Have an answer?

JD

Please login first before posting an answer.