Mona Coder
Mona Coder

Reputation: 6316

How to pass media queries with jQuery CSS method

I have a media query like this:

@media (min-width: 768px) {
  .navbar-nav > li > a {
    padding-top: 25px;
    padding-bottom: 25px;
  }
}

I need to change the style like:

 $( "#heightSet" ).change(function() {
              var choice = $(this).val();
              if (choice == "50"){
                $(".navbar-nav > li > a").css({"padding-top":"15px","padding-bottom":"15px"});
              }
                if (choice == "60"){
                $(".navbar-nav > li > a").css({"padding-top":"20px","padding-bottom":"20px"});
              }
});

How can I take care of the @media (min-width: 768px) on the .CSS() so the code is affected only on that specific view port?

Upvotes: 1

Views: 187

Answers (1)

isherwood
isherwood

Reputation: 61053

.my-class-15 {padding-top: 15px; padding-bottom: 15px;}
.my-class-20 {padding-top: 20px; padding-bottom: 20px;}

$("#heightSet").change(function () {
    var choice = $(this).val();

    if (choice == "50") {
        $(".navbar-nav > li > a").addClass('my-class-15');
    }
    if (choice == "60") {
        $(".navbar-nav > li > a").addClass('my-class-20');
    }
});

Here's a fiddle, but it's not very useful without your HTML.

http://jsfiddle.net/isherwood/nf5tP/

Upvotes: 1

Related Questions