EDIT: I found a real problem.
You referred to all the buttons on the page, and not to explicitly decide which of them.
$('button').click(function() {...});
Added ALL buttons to the dialog box - including those inside the dialog!
So, Iβll go step by step in the solution, but after finding out, I also found some other problems with your code, which are mostly semantic or bad practice, I will also consider them.
First of all, buttons! By providing some differentiation to these buttons than others, in other words, one common factor, you can make sure that you are not using the wrong buttons.
<div class="buttons"> ... </div>
And then:
$('.buttons').on('click', 'button', function() { ... });
Make sure I donβt access the buttons inside .
What caused this is what I call a double:
- Click β create dialogue
- Click the close button β close the dialog β open the dialog again (because it is also a button)
Now the problem causing the error is the part where you give the dialog a name:
.dialog('option', 'title', $(this).attr('title'))
^ here, because the button was a close button, you tried to address its name, and not, for example, the "Exclude" button, which leads to an error - because this dummy button was simply dropped! He also has no name!
This is why the error referred to the Exclude something object, which, obviously, is not an object, but the name of the dialog. The close button received an object identifier somehow between the close / open stage.
http://jsfiddle.net/ycZpQ/7/ <- here is the final JS script with the only dialog initialization and only if necessary will the dialog open, which is the most effective way to use this dialog system when the dialog is repeated, as in this case.
Notes on additional changes to the code: I made some changes to the way dialog creation looks, mostly semantic, but notice how I defined the buttons - the buttons object is an object with buttons for properties, not an array of button objects with properties. A little more effective and a little lighter on the eyes.