0

How to remove or disable jQuery properties (Class and Id) in media query css? I want to remove or disable the properties if it reaches to 991px size.

Here's my code.

    $(window).scroll(function() {
        if ($(this).scrollTop() > 1){  
            $('#stickyHeader').addClass("sticky01");
            $('.site-title').attr("id", "stSize");        
            $('#site-navigation').addClass("stNavSize");        
        }else{
            $('#stickyHeader').removeClass("sticky01");
            $('.site-title').removeAttr("id", "stSize");
            $('#site-navigation').removeClass("stNavSize");
            $('.site-title').addClass("stSize2");
            $('#site-navigation').addClass("stNavSize2");
        }
    });

Thanks for the help :)

3
  • "I want to remove or disable the properties if it reaches to 991px size" What is "it"? Do you mean window.innerWidth? Commented Apr 20, 2017 at 3:19
  • What is a "jQuery property"? Commented Apr 20, 2017 at 3:22
  • Nope. What I want to achieve is that when the browser is in 991px width all my jQuery properties will be disable Commented Apr 20, 2017 at 3:24

2 Answers 2

0

You could make a new class or id with 991px and set it's display=none,

@media you can addClass for screen larger than 991px

I hope it helps, otherwise write me in comment and I will be glad to help you

Sign up to request clarification or add additional context in comments.

Comments

0

CSS media queries to change elements at some viewport breakpoint

/* CSS for > 991px */

.element {
  color: red;
}

/* CSS for < 991px */

@media (max-width: 991px) {
  .element {
    color: blue;
  }
}

jQuery to add/remove classes, id's etc, on load and resize

$(window).on('load resize',function() {
 if ($(this).width() > 991) {
     $('#stickyHeader').addClass("sticky01");
 } else {
      $('#stickyHeader').removeClass("sticky01");
 }
});

5 Comments

Hello, I want to remove all of these in 991px: sticky01, stSize, stNavSize, stSize2, stNavSize2
"remove all of these" what do you mean? be more specific please.
Opps. I apologize. What i want to achieve is that when it reaches to 991px all the class and id that I made in jquery will be disable to stop the events from continuing
@MelvinRey then either use the media query example I gave to override the styles with whatever you wanted to do, or use jQuery to remove the classes/ID's that you applied.
991px is not a number.

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.