Error with "this" in IE with jQuery plugin
I'm coding a plugin for jQuery which now works fine on every browser but IE. This is part of the code:
(function( $ ){
$.fn.myPlugin = function(options) {
var methods = {
getFirstList: functio开发者_开发技巧n(el){
return $("ul:first", el);
}
};
return this.each(function(){
...
var list = methods.getFirstList(this);
// "this" here refers to window or document in IE.
...
});
};
})( jQuery );
When I call the plugin ($("#myObject").myPlugin();
), the keyword "this" is not refered to the DOM object, but to the window or document.
How do I fix this?
Try replacing this
with $(this)
精彩评论