Skip to content

Builder doesn't copy the style attribute correctly. #13

@wyuenho

Description

@wyuenho

Problem:

var div = Builder.node("div", {style: {top: 10px, left: 20px}});

Builder._attributes just copies the dict to the style member of the

HTMLElement, but this doesn't work quite right because browsers don't really know how to type convert a dict to a CSSStyleDeclaration object. So you are forced to use a really long text string.

It would be better if _attributes copies the attributes recursively. Something like this:

for (var attr in attributes) {
  attr = JSON.parse(attr);
    if (attr) {
       for (k in attr) {
          element[attr][k] = attr[k];
       }
    }
}

The actual code will of course need to prevent cyclic references and set a depth of the copying if needed. This should take care of the general case where one wants to set the properties of any nested objects on any DOM elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions