Clone HTML Element vs creating it with Javascript -
i'm getting list of employees via ajax request. i'm creating bunch of divs name address telephone etc. these new elements have buttons provide functionality. have been using approach:
var employee = function(params) { this.name = params.name; this.hrid = params.hrid; this.initialize = function() { this.container = document.createelement('div'); this.contname = document.createelement('div'); this.conthrid = document.createelement('div'); this.mybutton = document.createelement('button'); this.contname.innerhtml = this.name; this.conthrid.innerhtml = this.hrid; this.container.appendchild(this.contname); this.container.appendchild(this.conthrid); this.container.appendchild(this.mybutton); this.addobservers(); } this.addobservers = function() { this.mybutton.observer = this.dostuff.bind(this); this.mybutton.addeventlistener('click', this.mybutton.observer); } this.dostuff = function() { // stuff } }
this approach works me, i'm wondering if better off creating hidden div somewhere html built , cloning that.
i hear thoughts on approach better, or if it's six-of-one type of situation.
Comments
Post a Comment