I’d some experience in jquery but learning plugin creation right now. I’ve following javascript in html page
$("#testid").myplugin({});
In JQuery plugin, I have following code:
(function( $ ) {
$.fn.siddeffect = function (options) {
console.log(this.attr('id'));
console.log($(this).attr('id'));
return this;
};
})( jQuery );
I’m getting following in console
undefined
undefined
I tried few other combination as well but do not getting id (‘testid’ in above example). IS there any way to get calling id/selector within plugin?
PS: is present in html, as only element in body.
I think
should be
Or
$.fn.siddeffectshould change to$.fn.myplugin.I think you have typos in your original document.
Your code is working just fine. See here.