Get reference to element in jquery-ui dialog function
<p>Assuming the following markup</p>

<pre><code>&lt;div class="popup" data-title="Popup dialog title 1" data-modal="1" &gt;
    ...
&lt;/div&gt;
&lt;div class="popup" data-title="Popup dialog title 2"&gt;
    ...
&lt;/div&gt;
</code></pre>

<p>and the following javascript:</p>

<pre><code>$(".popup").dialog({
    title: '????', // Should be the value of the element's data-title attribute
    modal: ???, // Should be true if the element has a data-modal attribute
    ... etc, other options ...
});
</code></pre>

<p>I want to set the dialog title to the value of the "data-title" attribute on the popup element, and set modal based on the presence of the "data-modal" attribute.  How can I get a reference to the element - i.e. what can I replace '????' with in the above script?.  The first div should get the title "Popup dialog title 1" and the second "Popup dialog title 2".  The first div should be a modal popup, the second modeless</p>

<p><strong>UPDATED</strong></p>

<p>Answers to date have addressed the specific example, but the question was intended to be more general, though I'm not sure how to formulate the more general question.  Basically I want to be able to access attributes of the relevant element when behavior is attached to it using jQuery.  </p>

<p>I've updated the example to be more general.</p>

<p>I suspect the answer might involve calling <code>$(".popup").each</code> and attaching the dialog to elements inside the each, but as a jQuery beginner, I'm not sure of the most idiomatic way to do this.</p>

<p><strong>UPDATE 2</strong></p>

<p>I've implemented this using <code>.each</code> as in the following example.</p>

<pre><code>$(".popup").each(function() {
    var title = $(this).data('title');
    var modal = ($(this).data('modal') != null);
    $(this).dialog({
        title: title,
        modal: modal,
        ... etc ...
    });
});
</code></pre>

<p>I'd be interested to know if this is the most idiomatic / elegant way to achieve what I want.</p>
