2

I have this jquery code which runs fine.

$(window).load(function() {

    $('.menuBtn').click(function(e) {
        e.preventDefault();
        (this.classList.contains('is-active') === true) ? this.classList.remove('is-active'): this.classList.add('is-active');
        $('nav').slideToggle();

        $('.headerBarm').toggleClass('fixed-position');
        $('nav').toggleClass('fixed-position');
        $('.headerBar').toggleClass('fixed-position');


        $('body').css({
            'height': '100%',
            'overflow': 'hidden'
        });

    });

});

Recently I added the last line.

$('body').css({
                'height': '100%',
                'overflow': 'hidden'
            });

When i click on the button the above css gets added.

My problem is, when i click it again it doesn't change back. Could this work with a toggle kind of ?

2 Answers 2

5

Why don't you continue your streak of classes and toggleClass()?

CSS:

body.full {
    height: 100%;
    overflow: hidden;
}

JS (replace that last line):

$("body").toggleClass("full");
Sign up to request clarification or add additional context in comments.

3 Comments

Why was this answer downvoted so quickly? Please explain.
@mplungjan I guess that could be why. But I'm no code ninja that can copy a post and edit it in four seconds...
@mplungjan It's not about being "even" (I'm not much of a hardcore rep-gamer), but I was just wondering why it could be. But the downvote has been reversed. The last six comments are now irrelevant :)
3

Create a custom class and toggle it.

.myclass {
  height: 100%;
   overflow: hidden;
}



$('body').toggleClass('myclass');

2 Comments

CSS classes don't have quotations around them.
@JonathanLam Thanx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.