Is it possible to define a on click event inside an object (oop)? I'm new to this. I have been trying the following: (I simplified the code (no CSS of div etc))
function menu_item(menu_name){
this.menu_name=menu_name;
this.create = function(){
$('body').html("<div id=" + menu_name + " />");
};
$('#' + menu_name).on('click',function(){
alert (menu_name);
});
}
menu_item("test");
menu_item.create();
Now when I click on the div with id of the given menu_name, I want to alert the name (as a test) but this isn't working... is this even possible?