Can Anybody explain why this happen?
This is my code in a plugin called something:
(function($){
$.fn.extend({
something: function(options) {
// Here I define defaults
$(this).bind('change', function () {
return $(this).each(function() {
// a function body
});
});
}
});
})(jQuery);
and I call this plugin in another js like this:
var myarray=new Array();
myarray[0] = $('#selector').something({
regex:/^([\u0600-\u06FF]|\s)*$/,
// another options
});
$('#selector').change(function (){
alert (myarray[0]);
});
in every change in my selector it returns me undefined.
It completely make me insane. Thanks if anyone can help me.
Edit:
You Can Read My complete code here.
In your plugin you are just attaching a
changeevent handler on the element which just runs a loop on all the matched set of elements and returns a jQuery object.If you want to return something from
somethingplugin then the return statement should be outside the event handler.Now you can use this
Note that
myarraywill be an array because jQueryeachreturns a jQuery object which itself is an array of DOM elements.