I’m trying to write a jquery plugin and i have a question about the famous “this”.
Here is the call of the custom plugin :
$('.selector').myPlugin({
test: $(this).attr('rel')
});
And now, somewhere in my plugin :
$.myPlugin = function (options) {
alert(options.test);
}
My question is : How can i use the Rel attribute of my selector in the plugin using $(this)?
The previous code is always telling me that “this” is the Document.
Thanx a lot
$(this)isn’t what you expect it to be in that object literal. Loop usingeach:Inside
each,thiswill point to the correct element, as opposed to the context of the calling function.