Как закрыть все открытые поля dialog
в jQuery
?
Ситуация следующая: у меня простая страница без диалогов. У него есть несколько кнопок, которые открывают для себя диалоги.
Когда я нажимаю кнопку, мне нужно закрыть все открытые диалоги.
Вот HTML:
<div id="buttons">
<a href="#" id="btn_1">Button 1</a>
<a href="#" id="btn_2">Button 2</a>
<a href="#" id="btn_3">Button 3</a>
</div>
<div id="dialog_1" class="dialogbox">...</div>
<div id="dialog_2" class="dialogbox">...</div>
<div id="dialog_3" class="dialogbox">...</div>
И вот jQuery:
$(function() {
$('#buttons').find('a').click(function() {
// close all dialogs
$('.dialogbox').dialog("close");
// find out clicked id and open dialog
var nr = this.id.split("_")[1];
$('#dialog_'+nr).dialog();
});
});
В Chrome говорится: Uncaught Error: cannot call methods on dialog prior initialization; attempted to call method 'close'
.
Я попытался проверить $('.dialogbox').dialog('isOpen')
, но тот же результат.
Как закрыть все диалоги?