tags:

views:

34

answers:

2

Hey guys I have a quick question, I have a dialog box that has multiple links with different attributes. Each time a link is clicked, the attribute src is printed inside of the dialog box so that each link has a unique output in the dialog. My problem is simply that only the first src title is in every box and I would like to change that as well with each click. I separated the line containing title to show the problem. If anyone has any ideas I would appreciate it. EDIT

<a class="open" src="something" title="Click to play">link</a>
<a class="open" src="something else" title="Click to play">link2</a>

$(function() {

$(\"#show\").dialog({
hide: 'clip', 
width: 400,
height: 150,
position: 'center',
show: 'clip',stack: true, 
minHeight: 25,
minWidth: 100, 
autoOpen: false,
resizable:false});

$('.open').click(function() {
var src=$(this).attr('src');
$('#show').html(src);
$('#show').dialog({ title: src }).dialog('open');
  })

 });
A: 

Update jQuery UI Title

$('#show').data('title.dialog', 'new title');
gmcalab
+1  A: 

You need to either create the dialog outside your function once, and set the title, or destroy the previous dialog.

To destroy the previous one and create a new one each click:

$("#show").dialog("destroy").dialog( { options });

To just set the title and text each time and create the dialog once (better approach):

$("#show").dialog({
  hide: 'clip', 
  width: 400,
  height: 150,
  position: 'center', 
  show: 'clip',
  stack: true,
  minHeight: 25, 
  minWidth: 100, 
  autoOpen: false,
  resizable: false
});
$('.open').click(function() {
  var src = $(this).attr('src');
  $('#show').html(src).dialog('option', 'title', src).dialog('open');
  //or...
  $('#show').html(src).dialog('option', {title: src}).dialog('open');
});
Nick Craver
beautiful thanks Nick
Scarface
thanks again Nick but when I try the second method, the title is blank
Scarface
I updated my post to show what I used
Scarface
src is defined for sure because the content is changing, it has to do with .dialog({ title: src }) because the title is still blank regardless of what I change that title to.
Scarface
@Scarface - I had `.html($(this).attr('src'))` in there, that's why the content part worked but the title didn't, now both are using the `src` variable.
Nick Craver
I meant no matter what I change the title to in dialog({ title: src }) the title will not show. I pasted the exact code I am using, I could change the title to $('#show').dialog({ title: 'test' }).dialog('open'); and I still get nothing but the content is still defined as it should be. The only way the title shows is if I put it in the original dialog function outside the click function.
Scarface
@Scarface - Try the updated answer, the default UI options behavior is a bit different from my custom extensions, woops.
Nick Craver
lol that did it Nick (I used the first one), thanks a lot for your time.
Scarface