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

后端 未结 11 615
慢半拍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:33

    To directly answer the question: style['text-align'] is how you would reference a property with a hyphen in it. But style.textAlign (or style['textAlign']) is what should be used in this case.

提交回复
热议问题