I would like to set the overflow-x
css property with jQuery, but it doesn't work:
$('.mySelector').css({
color: 'Red',
overflow: 'auto',
overflow-x: 'scroll'
});
How would I set properties that have a '-' (dash) in them?
The overflow-x property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the left and right edges.
The jQuery css() method is used to get the computed value of a CSS property or set one or more CSS properties for the selected elements.
You can use the css method to change a CSS property (or multiple properties if necessary): $("#business"). click(function(event){ jQuery. fx.
jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.
You could use either camel-case:
$('.mySelector').css({
color: 'Red',
overflow: 'auto',
overflowX: 'scroll'
});
Or quoted keys:
$('.mySelector').css({
color: 'Red',
overflow: 'auto',
'overflow-x': 'scroll'
});
I would recommend quoted keys, I find it easier to tell 'at a glance' what a rule is compared to camel-casing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With