As in this example, i like to create HTML elements and attach them onclick functions that is part of the object instance, any way to do this? when clicking it getting :
Uncaught ReferenceError: getObj is not defined
function DataSources() {
var newCheckbox = document.createElement("input");
newCheckbox.type = "checkbox";
newCheckbox.addEventListener("click", function() {
this.ds_checkbox("test2");
}, false);
document.getElementById("multi_select").append(newCheckbox);
this.addLabel = function() {
var label = document.createElement('label');
label.innerHTML = "test";
label.addEventListener("click", function() {
this.getObj("test");
}, false);
document.getElementById("multi_select").append(label);
}
this.getObj = function(key) {
console.log(key);
};
this.ds_checkbox = function(p) {
console.log(key);
};
}
var datasources = new DataSources();
datasources.addLabel();
<div id="multi_select">
</div>