i am trying to learn building own jquery plugin . with the simple example but i am getting error while executing it .planning to build plugin for
Loan calculator
can some help me regarding error “
Object Expected
my javascript in the index.html goes like this …
$(function(){
$('#btn').click(function() {
var roi=getie(); // ROI - rate of interest - value of i receved from function getie()
$("#i").val(roi); // input type 'text ' to display Interest (i) value
});
});
and the plugin codgin for custom function
getie()
goes like this in separate
calculate.js file
CODE :
(function($){
//Attach this new method to jQuery
$.fn.extend({
//This is where you write your plugin's name
getie: function() {
//Iterate over the current set of matched elements
return this.each(function() {
var i=20;
return i;
});
}
});
})(jQuery);
i am using jquery-1.7.2.min.js and query-ui-1.8.20.custom.min.js as other js file in this .
With
$.fn.extendyou extend jquery and don’t create an object. So you must call it on a jquery object: