separ1 separ1 - 21 days ago 6
AngularJS Question

How to add focus on the cancel label of the popup?

I have this popup function. It has a template for the pop up. Has one delete and cancel button. I want to have focus on the cancel button when the popup opens. How can i do that?

$scope.Popup = function(funcname){
alert_template({
id: '',
title: '',
scope: $scope,
template: '<div class=""><span>Delete the selected item?</span></div>',
success: {
label: 'Delete',
fn: function(){
//Do Something
}
},
cancel: {
label: 'Cancel',
fn: //Do Something

}
});

Answer

Versions of JS differ you may or not need the # to identify the object.

JavaScript:

document.getElementById('cancel').focus();

jQuery:

$('#cancel').focus();

Comments