How do I reference a javascript object property with a hyphen in it?

Using this script to make a style object of all the inherited etc styles.

var style = css($(this));
alert (style.width);
alert (style.text-align);

with the following, the first alert will work fine, but the second one doesn’t.. it’s interpreting the - as a minus I assume.. the debugger says ‘uncaught reference error’. I can’t put quotes around it, though, because it isn’t a string. So how do I use this object property?

74 thoughts on “How do I reference a javascript object property with a hyphen in it?”

Leave a Comment