Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set overflow-x with jQuery? Or: How to set css-properties with a '-' (dash)?

Tags:

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?

like image 235
Kees C. Bakker Avatar asked Jun 10 '11 13:06

Kees C. Bakker


People also ask

What does overflow X do in CSS?

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.

Which jQuery method is used to get or set a CSS property value?

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.

Can we change CSS properties values using jQuery?

You can use the css method to change a CSS property (or multiple properties if necessary): $("#business"). click(function(event){ jQuery. fx.

What is the use of CSS () method in jQuery?

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.


1 Answers

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.

like image 111
Michael Robinson Avatar answered Sep 29 '22 02:09

Michael Robinson