I have JQuery li element that I want simulate the click on. I've written a small function in angular to do so, but it doesn't seem to be working.
settings.triggerClick = function (levels) {
for (var i = 0; i < levels.length; i++) {
$("#Monday-" + levels[i].LevelCode + "-tab").trigger("click");
}
}
This is called here:
// Get Service Levels to Build Delivery Rules Accordion
settings.getDeliveryServices = function() {
$http.get(resourceBase + "api/service/levels").success(function(data) {
settings.serviceLevels = data;
// Get Service Days
$http.get(resourceBase + "api/service/days").success(function(days) {
settings.serviceDays = days;
// Build the Accordion
settings.accordian(settings.serviceLevels);
settings.triggerClick(settings.serviceLevels);
});
});
}
The getDeliveryServices function is called when the page / angular load.
I've debugged through and so far I've ruled out the serviceLevels being empty, so there shouldn't be an issue there. I've also made sure the debugger is entering the for loop. When I get that element using the console it finds the correct JQuery dom element. So I'm not sure what the problem is. Could also be worth mentioning that the elements are generated by an angular ng-repeat loop.
<li id="{{day.Day}}-{{level.LevelCode}}-tab" ng-repeat="day in settings.serviceDays">
<a id="{{day.Day}}-{{level.LevelCode}}" href="#tabContent-{{day.Day}}-{{level.LevelCode}}" ng-click="settings.changeTab(day, level, $event)">{{day.Day}}</a>
</li>
So I don't know if it's got something to do with the elements not being available before I look for them, however I assume that's not the issue because I'm calling the settings.triggerClick() method inside a success/error promise.