so wrote a simple script:
function Component(renderTarget){
this.target = document.querySelector(renderTarget);
this.number = 0;
this.increment = 1;
this.goUp = function(){
this.number = this.number + this.increment;
this.render();
}
this.goDown = function(){
this.number = this.number - this.increment;
this.render();
}
this.render = function(){
this.target.innerHTML = '';
this.target.innerHTML += `
<div class="container">
<div class="number">${this.number}</div>
<div class="selector">
<div class="up"><i class="fa fa-chevron-up" aria-hidden="true"></i></div>
<div class="down"><i class="fa fa-chevron-down" aria-hidden="true"></i></div>
</div>
</div>`;
}
this.init = function(that){
that.render();
}(this);
}
var myComponent = new Component('.target');
which basically renders some HTML to a div with the class "target". Now, I want to add an event listener to .up and .down and bind them to the component functions. Which is the correct way of doing this?
You can fork this codepen.
Thanks in advance!
PS: I know I can use class and arrow functions, etc. but this is just for testing.
EDIT: Working version. This works but I don't know if it's the correct way of doing it.