my plugin
$.fn.myplugin=function(){
var element=$('<div/>').addClass('select').appendTo(this);
return this;
}
and script
$('<div/>').myplugin().appendTo('body');
problem is element not appending.
It works as is: http://jsfiddle.net/7n2Bd/
But you will have a problem if you are passing a collection of elements. Try this:
$.fn.myplugin=function() {
return this.each(function() {
$('<div>').addClass('select').appendTo(this);
});
};
It seems you code is OK.
$.fn.myplugin = function() {
// hello is for just view purpose
$('<div>hello</div>').addClass('select').appendTo(this);
return this;
}
$('<div/>').myplugin().appendTo('#target'); // here instead of '#target' use 'body'
$.fn.myplugin = function() {
return $.each(this, function() {
$('<div>hello</div>').addClass('select').appendTo(this);
});
}
Put all your code within $(document).ready({ .. }).