I am trying to write a plugin in jQuery, but I am getting "undefined is not a function" in this part:
(function($) {
$.fn.build = function(options){
var settings = $.extend({
x: 0,
y: 0,
type: 0
}, options);
$.post("/build", { x: settings.x, y: settings.y, type: settings.type}, function(data) {
// Return JSON array
if(data['doBuild'] == 'true') {
this.append("<div class='item' style='left:"+settings.x+"px; top:"+settings.y+"px;'></div>"); // ERROR ON THIS LINE
}
},'json');
return this;
};
}(jQuery));
I think that it has to do with the 'this' statement, but I don't understand the error. Why doesn't it work?