Bootstrapと相互作用するjQueryプラグインを作成していますが、jQuery要素で関数を呼び出すと次のエラーが発生します。
Uncaught TypeError: Object [object Window] has no method 'each'
これは問題のJavaScriptです:
!function ($) {
$.fn.alertAutoClose = function (interval) {
setTimeout(function () {
return $(this).each(function () {
$(this).hide();
});
}, interval);
}(window.jQuery);
プラグインは次のようにトリガーされます。
$(".alert").alertAutoClose(1000);
これはページ上のHTMLです:
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>