Is there a way to get the element inside a function in an object that was set as ‘data’ of an element? If there is none, what are some alternative ways to implement this?
var m = function(options){
// Some initialization code here
}
m.prototype.doSomething: function() {
// How do i get the #an_element here?
}
$("#an_element").data('myObject', m);
The easiest way to do that it’s to give that element to constructor, you can check it on jsfiddle.
The mistake what you did it’s that you trying to put into data the function itself, but you have to create a object before like this:
$("#an_element").data('myObject', new m());