Here is jQuery code:
<script>
$(document).ready(function() {
$('.class112').click(function() {
var msg = $(this).attr('id');
$('#'+msg).dialog({
autoOpen:false,
width:100,
height:200,
position:[250,50]
});
$('#'+msg).load('classSource/'+msg+'.html');
$('#'+msg).dialog('open');
});
});
</script>
and HTML code:
<p class="class112" id="class1">open it dude! </p>
<p class="class112" id="class2">open2 dude!</p>
my purpose is whenever user clicks one of paragraphs mentioned above, a jQuery user interface dialog window shows up with the related HTML filed loaded inside. It works fine but the think is when I click to the paragraphs, they disappear after clicking. Where I am doing wrong?
You’re turning your paragraphs into dialogs right here:
As soon as you do that, jQuery-UI will hide your paragraph until you open the dialog with this:
and then it’ll get hidden again when you close the dialog.
You probably want a dedicated element for the dialog. Create an HTML element for the dialog and start it off hidden:
And then use that as the dialog:
Notice that I’ve also moved the
.dialog('open')call to theloadcallback, that way the dialog won’t open until the appropriate content has been loaded; you might want to add a little animated “loading” GIF of some sort as well.If you want multiple dialogs open at the same time then you’ll have to adjust the above a little bit, adding a separate
<div id="X-dialog">, whereXis the paragraphid, would be a pretty easy way to arrange that.