I have a class like below and I want to pass an element for further customization. The class should be responsible of setting up the size of the box and adds elements to it. I having hard time applying the necessary styles needed to element.
class BoxBuilder {
constructor(element, items) {
this.items = items;
this.elm = document.getElementById(element);
}
setSize(h, w) {
console.log(this.elm); // returns null
this.elm.style.width = w;
this.elm.style.height = h;
return this;
}
}
And with jQuery :
class BoxBuilder {
constructor(element, items) {
this.items = items;
this.elm = $(element);
}
setSize(h, w) {
console.log(this.elm); // returns [context: document, selector: "#box-container"]
this.elm.style.width = w;
this.elm.style.height = h;
return this;
}
}
// here is what I am trying to achieve
var box = new BoxBuilder('#box-container').setSize(300, 250);