After every two seconds, my JavaScript function is triggered and based on certain logic, I aim to add a CSS class with an effect to an HTML element on the page.
var counter = 0;
$interval(function () {
counter++;
doSomething();
$('#myElem_' + counter).addClass('myClass');
}, 2000);
function doSomething() {
if (counter <= 35) {
if (counter == 0) {
$scope.myIndex = 1;
} else {
$scope.myIndex = counter;
}
} else {
// not implemented
}
}
The CSS class is only applied to the HTML element the first time. The counter functions properly but the CSS class can only be added to the first element.
The HTML page contains unique ID numbers for HTML elements, such as
<div id="myElem_1"></div>
<div id="myElem_2"></div>