переопределение свойства стиля набора javascript - PullRequest
0 голосов
/ 21 мая 2018
(function (constructor) {
  if (constructor && constructor.prototype) {

    //Custom - styleMe
    Object.defineProperty(constructor.prototype, 'styleMe', {
      get: function () {
        if (this == null) return {};
        return (window.getComputedStyle ? getComputedStyle(this, null) : this.currentStyle);
      },
      set: function (key, newValue) {
        this.styleMe.key = newValue;
      }
    });
  }
})(window.Node || window.Element);

Я могу легко get значение стиля как:

var marginTop = document.getElementById("myID").styleMe.marginTop;

Но как установить значение?Это не работает:

document.getElementById("myID").styleMe.marginTop = "30px";
...