0

I have a class which uses a media query:

css:

@media only screen and (min-width: 58.75em)
.top-bar-section ul li {
  border-left: 1px solid #fff;
  transform: skewX(15deg);
}

Now if the value of City() is London I want to change that css above to say:

 @media only screen and (min-width: 58.75em)
    .top-bar-section ul li {
      border-left: 1px solid #fff;
      transform: skewX(-15deg);
    }

My javascript is:

if (City() == "London"){
//change the css class from the first example to the 2nd?
}

Any help on how I can do this with jQuery to change a classes css? Thanks, Josh

5

4 Answers 4

2

For specifying the css you can use the .css()-function of jQuery:

$('.top-bar-section ul li').css({
  '-webkit-transform' : 'skewX(-15deg)',
  '-moz-transform'    : 'skewX(-15deg)',
  '-ms-transform'     : 'skewX(-15deg)',
  '-o-transform'      : 'skewX(-15deg)',
  'transform'         : 'skewX(-15deg)'
});

Demo

Or you can specify a second class, e.g.:

.top-bar-section ul li.london {
    transform: skewX(-15deg);
}

and call

$('.top-bar-section ul li').addClass('london');

inside your if-condition. For removing the class you can use .removeClass()

Reference

.css()

.addClass()

.removeClass

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

Comments

0

yes you can do with the help of jQuery, by adding jQuery newClass if specified condition is true, and use jQuery removeClass vice-versa.

Comments

0

you can use addClass and removeClass methods to make it.

Comments

0

you can change classes using jQuery with the class attributes, here's the documentation

Comments

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.