I have a case where I need to update the header of the jQuery UI dialog with the part number whenever the table cell is double clicked. The name will be obtained from the table cell value itself.
This snippet (below) from the actual code works, but it just doesn't seem right to me, since I have to call the dialog function twice: (1) to change the name and (2) open the dialog box.
Is there a better way to combine both operations with a single .dialog () call?
Js snippet
var my_dlg = $('<div id="my-dlg">')
.html(
'<span class="part">FOO BAR</span>'
)
.dialog({
autoOpen: false,
title: 'Default Title',
modal: true
});
$('td.part').live('dblclick', function(){
$(my_dlg)
.dialog('option','title', $(this).text())
.dialog('open');
});
HTML snippet
<table>
<tr><td class="part">AB123456</td></tr>
<tr><td class="part">GX443459</td></tr>
<tr><td class="part">SK555455</td></tr>
</table>
source
share