Calling a jQuery widget method
Hi,
I am trying to create a plugin for creating modals with jQuery UI
doing:
$.widget("ui.modal", {
_init: function(){
$(this.element).each(function(){
var offset = $(this).offset();
$(this).data("modal",$("<div/>"));
$(this).data("modal")
.width($(this).width())
.height($(this).height())
.css({
left: offset.left,
top: offset.top
})
.addClass("modal")
.appendTo(document.body);
$(this).data("modal")
});
},
destroy: function(){
$(this.element).each(function(){
if ( $(this).data("modal") ){
$(this).data("modal").remove();
$(this).data("modal",null);
}
});
}
});
After I have done $("#myElement").modal(), I'd like to destroy it from
outside the widget, but I can't figure out how to call my method
destroy().
I tried $("#myElement").modal("destroy") without success (tried with
just an alert message in the destroy function, and it didn't work
either).
Can you help?
Thanks!