Event handling on jQuery this
function Car(id) {
var $this = this;
this.init = function() {
this.el = document.getElementById(id);
$(this).on('keypress', function(e){
alert(e.target);
});
}
}
The alert never happens. If I change $(this) to #hero. It works. I can't
see why.
$(document).ready(function(){
var hero = new Car("hero");
hero.init();
});
No comments:
Post a Comment