Reputation: 263
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
Upvotes: 0
Views: 95
Reputation: 7878
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)'
});
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
Upvotes: 2
Reputation: 54
you can change classes using jQuery with the class attributes, here's the documentation
Upvotes: 0
Reputation: 2480
yes you can do with the help of jQuery, by adding jQuery newClass
if specified condition is true, and use jQuery removeClass
vice-versa.
Upvotes: 0