Daniel T.
Daniel T.

Reputation: 38390

How do I open a jQuery dialog and auto-set its title to the attribute in the HTML tag?

I have a div that I'm setting a title attribute on:

<div id="test" title="Test Dialog">Some test</div>

Then I open a dialog with it:

$('#test').dialog({
    title: $(this).attr('title')
});

The first time this dialog opens, the title is set successfully. However, if I close the dialog and re-open it, the title will be blank. This is because, the first time jQuery opens the dialog, it copies the element and removes the title tag. Is there a way to get the behavior I want, where it reads the title from the title attribute every time?

Upvotes: 0

Views: 201

Answers (1)

Constantinius
Constantinius

Reputation: 35039

I'd do this in the open event, like so:

$("#test").dialog({
   open: function(event, ui) { 
      $(this).dialog( "option", "title", $(this).attr('title') );
   }
});

Upvotes: 1

Related Questions