i want to call variable "info" when user click on div
the code supposed to print "success"
but its print "undefined"
html
<div id="container" style="width: 100px; height: 100px; border: solid black 1px">
javascript
window.onload = function(){
var Controller = function(){
this.info = ' success ';
this.listener = function(){
alert( this.info );
}
this.set = function( ele ){
ele.onclick = this.listener;
}
}
var target = document.getElementById('container');
var controller = new Controller();
controller.set( target );
}
my goal
- i need to call variable "info" inside Controller listener
- i need to give action click inside Controller set
my problem is inside function "listener",
keyword "this" refer to div element, not class Controller
how to call variable info inside function "listener" ?