Michael Rogers
Michael Rogers

Reputation: 99

Adding CSS with JQuery to Multiple Classes

I'm trying to add

.km-android div.km-view {
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
}

when a specific condition is meet in javascript.

I've tried adding

$('.km-android, div.km-view').css('-webkit-box-direction', 'normal');       
$('.km-android, div.km-view').css('-webkit-flex-direction', 'column');

but that isn't working any suggestions would be great

Thanks

Upvotes: 0

Views: 1787

Answers (3)

matewka
matewka

Reputation: 10148

Remove the comma from the jQuery selector. You can also use camel case properties:

$('.km-android div.km-view').css({
    webkitBoxDirection: 'normal',
    webkitFlexDirection: 'column'
});

Upvotes: 0

Roy M J
Roy M J

Reputation: 6938

Try :

$('.km-android div.km-view').css({'-webkit-box-direction': 'normal','-webkit-flex-direction': 'column' });  

Upvotes: 0

hsz
hsz

Reputation: 152236

In your JS you have , which doesn't appear in CSS. Try with:

$('.km-android div.km-view').css('-webkit-box-direction', 'normal');       
$('.km-android div.km-view').css('-webkit-flex-direction', 'column');

or even simplier:

$('.km-android div.km-view').css({
    '-webkit-box-direction': 'normal',
    '-webkit-flex-direction': 'column'
});

However Nick R has right - put this CSS in another class and just add this class to the element if met conditions, so:

.met-conditions {
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
}

and JS:

$('.km-android div.km-view').addClass('met-conditions');

Upvotes: 1

Related Questions