I am using angularjs to add dynamic column and its working fine. But the problem is that when I am adding it from function want to set focus to dynamically added element, but if I try after adding function the dom said that element is not yet created. For detail please have look at my code.
$scope.addCol = function(){
//to add column dynamically assign one object to column
$scope.column.push({
spName: "",
spId: 0,
claimedId: 0
});
var id = $scope.column.length - 1;
if($('#sptext'+id).length == 0){
alert("Element was not found");
}else{
alert("Element was found");
$('#sptext'+id).focus();
}
},
Here after adding column the flow goes inside Element was not found.
HTML Code:
<table class="table-striped" id="mainTable" name="mainTable">
<thead style="border-bottom: 1px solid #dddddd;">
<tr ng-if="$index == 0 && counter > 2" ng-repeat="rowContent in rows" id="{{$index}}">
<td name="{{rowContent}}1">
<span >Heading / Question</span>
</td>
<td ng-repeat="colContent in column" id="sp{{$index}}{{$parent.$index}}">
//this span(element) I am trying to set focus while creating dynamically
<span contenteditable id="sptext{{$index}}" >{{colContent.spName}}</span>
<p style="display: none;">{{colContent.spId}}</p>
</td>
</tr>
</thead>
</table>
I am trying to set focus to `<span>` element but its not working.
Please give me any suggestion. Thanks.