0

What is difference betweet betweet element.style['property']='value' and element.style.property='value' for manipulate style in javascript?

user2799274
  • 133
  • 1
  • 1
  • 9
  • possible duplicate of [JavaScript property access: dot notation vs. brackets?](http://stackoverflow.com/questions/4968406/javascript-property-access-dot-notation-vs-brackets) – Josh Lee Sep 20 '13 at 17:38

2 Answers2

1

There is no difference it's just different syntax

In JavaScript, objects are also associative arrays (or hashes). That is, the property

theStatus.Home

can also be read or written by calling

theStatus['Home']

Objects as associative arrays

Working with objects

Alex Art.
  • 8,711
  • 3
  • 29
  • 47
0

There is a difference in this case, but I believe it's non-standard and browser-dependent: in Chrome, bracket notation allows you to reference style properties using their actual CSS name, instead of the camelCased version. In Firefox, it doesn't work. I haven't tested other browsers.

You can try it with Chrome on this very page, from the console:

document.body.style['background-color'] = 'red'
bfavaretto
  • 71,580
  • 16
  • 111
  • 150