set focus on second element in jquery UI


I can't seem to set the focus on the second button (the _no) button. Everything else works fine but the focus remains constantly on the yes button.


$("#dialog-DeleteFave").dialog({ 
			
			buttons: [{ 
				text : _yes, 
				click :function() {
						var FaveToDelete = $("select[name=selectFavorite]").val();	
						$.ajax({
						   type: "POST",
						   url: "/aaMain/ajaxDeleteFavorite.php?FaveToDelete="+FaveToDelete,
						   //data: $("form[name=filters]").serialize(),
						   success: function(msg){	document.filters.runButton.value=1;
	 									document.filters.submit();
							  }
						});
					
						// then close

						$(this).dialog("close");}
					},
					{ 
				text : _no,
				click: function() {
						$(this).dialog("close");} 
					}]
			,
			width:500,
			autoOpen: false,
			modal: true,
			open: function() {
  
        $(this).parent('.ui-dialog-buttonpane button:eq(1)').focus(); 
				}
		});

Open in new window

gbeaulacAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
You may use :
			open: function() {
				var container = $("#dialog-DeleteFave").parent();
				$(".ui-button-text:contains('" + _yes + "')", container).parent("button.ui-button").focus();
			}

Open in new window

0
leakim971PluritechnicianCommented:
Test page :

(you can change _no by _yes)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script> 
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.2.js" type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script> 
<script language="javascript">
	$(document).ready(function() {
		var _yes = "YES";
		var _no = "NO";
		$("#dialog-DeleteFave").dialog({ 
			buttons: [
				{ 
					text : _yes, 
					click :function() {
						var FaveToDelete = $("select[name=selectFavorite]").val();	
						$.ajax({
							type: "POST",
							url:"/aaMain/ajaxDeleteFavorite.php?FaveToDelete="+FaveToDelete,
							success: function(msg){	document.filters.runButton.value=1;
								document.filters.submit();
							}
						});
						$(this).dialog("close");
					}
				},
				{ 
					text : _no,
					click: function() {
					$(this).dialog("close");} 
				}
			],
			width:500,
			autoOpen: false,
			modal: true,
			open: function() {
				var container = $("#dialog-DeleteFave").parent();
				$(".ui-button-text:contains('" + _no + "')", container).parent("button.ui-button").focus();
			}
		});
		$("input").click(function() {
			$("#dialog-DeleteFave").dialog("open");
		});
	});
</script>
</head>
<body>
<input type="button" value="OPEN" />
<div id="dialog-DeleteFave" title="Save settings" >
	<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gbeaulacAuthor Commented:

Its giving focus to the yes and the no button.

It was already automatically giving focus to the _yes button, but I need it to give focus to the _no instead.  
0
gbeaulacAuthor Commented:
Just had to add

$(".ui-button-text:contains('" + _yes + "')", container).parent("button.ui-button").blur();

and got it to only focus the _no

Thank you again!
0
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.