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

后端 未结 11 606
慢半拍i
慢半拍i 2020-11-22 06:07

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);

11条回答
  •  伪装坚强ぢ
    2020-11-22 06:42

    I think in the case of CSS styles they get changed to camelCase in Javascript so test-align becomes textAlign. In the general case where you want to access a property that contains non-standard characters you use array-style. ['text-align']

提交回复
热议问题