Assuming the following markup
<div class="popup" data-title="Popup dialog title 1" data-modal="1" >
...
</div>
<div class="popup" data-title="Popup dialog title 2">
...
</div>
and the following javascript:
$(".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 ...
});
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
UPDATED
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.
I've updated the example to be more general.
I suspect the answer might involve calling $(".popup").each 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.
UPDATE 2
I've implemented this using .each as in the following example.
$(".popup").each(function() {
var title = $(this).data('title');
var modal = ($(this).data('modal') != null);
$(this).dialog({
title: title,
modal: modal,
... etc ...
});
});
I'd be interested to know if this is the most idiomatic / elegant way to achieve what I want.