Hi all, I am trying to make a auto blinking div but while trying to achieve using setTimeout its saying " this.off is not a function" in on method I tried two variations. Please help !!!
var Light = function(color) {
this.color = color;
};
Light.prototype = {
ref:null,
defColor:'black',
on:function(){
if(this.ref != null){
this.ref.css('background-color',this.color);
window.setTimeout(function(){this.off()}, 5000);
//window.setTimeout(this.off, 5000);
}
},
off:function(){
if(this.ref != null){
this.ref.css('background-color',this.defColor);
window.setTimeout(function(){this.on()}, 5000);
//window.setTimeout(this.on, 5000);
}
}
};
var l1;
$(document).ready(function(){
l1 = new Light('red');
l1.ref=$('#mydiv');
l1.on();
});